<commit_before>##
# Profile runtime definitions
module BoxenProfiler
  # rubocop:disable Metrics/LineLength
  REGEX_PATTERNS = [
    /^Info: .*(?<class>[^\[]+)\[(?<name>[^\]].+)\]: Evaluated in (?<time>[\d\.]+) seconds$/,
    /^Notice: Compiled (?<class>catalog) .* environment (?<name>[^ ]+) in (?<time>[\d\.]+) seconds$/
  ]
  # rubocop:enable Metrics/LineLength

  DEFAULT_RESULT_COUNT = 100

  ##
  # Profiler runtime class
  class Profiler
    def run!
      results = parse(`#{command}`.split("\n"))
      results.sort! { |a, b| b.last <=> a.last }
      write results
    end

    private

    def write(results)
      results.lazy.take(DEFAULT_RESULT_COUNT).each do |pclass, name, time|
        puts "#{time} - #{pclass}[#{name}]"
      end
    end

    def parse(lines)
      lines.each_with_object([]) do |line, acc|
        next unless REGEX_PATTERNS.find { |pattern| line.match(pattern) }
        pclass, name, time = Regexp.last_match[1..3]
        time = time.to_f
        acc << [pclass, name, time]
      end
    end

    def command
      'boxen --profile'
    end
  end
end<commit_msg>fix color errors<commit_after>##
# Profile runtime definitions
module BoxenProfiler
  REGEX_PATTERNS = [
    /^Info: .*([^\[]+)\[([^\]].+)\]: Evaluated in ([\d\.]+) seconds$/,
    /^Notice: Compiled (catalog) .* environment ([^ ]+) in ([\d\.]+) seconds$/
  ]

  DEFAULT_RESULT_COUNT = 100

  ##
  # Profiler runtime class
  class Profiler
    def run!
      results = parse(`#{command}`.split("\n"))
      results.sort! { |a, b| b.last <=> a.last }
      write results
    end

    private

    def write(results)
      results.lazy.take(DEFAULT_RESULT_COUNT).each do |pclass, name, time|
        puts "#{time} - #{pclass}[#{name}]"
      end
    end

    def parse(lines)
      lines.each_with_object([]) do |line, acc|
        next unless REGEX_PATTERNS.find { |pattern| line.match(pattern) }
        pclass, name, time = Regexp.last_match[1..3]
        time = time.to_f
        acc << [pclass, name, time]
      end
    end

    def command
      'boxen --profile --no-color'
    end
  end
end
{'fraction_non_alphanumeric': 0.16912815626488803, 'fraction_numerical': 0.004764173415912339, 'mean_word_length': 2.5294117647058822, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7194719', 'n_tokens_mistral': 763, 'n_tokens_neox': 737, 'n_words': 170}