<commit_before># frozen_string_literal: true

require "rails/code_statistics_calculator"
require "active_support/core_ext/enumerable"

class CodeStatistics #:nodoc:
  TEST_TYPES = ["Controller tests",
                "Helper tests",
                "Model tests",
                "Mailer tests",
                "Job tests",
                "Integration tests",
                "System tests"]

  HEADERS = { lines: " Lines", code_lines: "   LOC", classes: "Classes", methods: "Methods" }

  def initialize(*pairs)
    @pairs      = pairs
    @statistics = calculate_statistics
    @total      = calculate_total if pairs.length > 1
  end

  def to_s
    print_header
    @pairs.each { |pair| print_line(pair.first, @statistics[pair.first]) }
    print_splitter

    if @total
      print_line("Total", @total)
      print_splitter
    end

    print_code_test_stats
  end

  private
    def calculate_statistics
      @pairs.transform_values { |dir| calculate_directory_statistics(dir) }
    end
<commit_msg>Partly revert `calculate_statistics` change<commit_after># frozen_string_literal: true

require "rails/code_statistics_calculator"
require "active_support/core_ext/enumerable"

class CodeStatistics #:nodoc:
  TEST_TYPES = ["Controller tests",
                "Helper tests",
                "Model tests",
                "Mailer tests",
                "Job tests",
                "Integration tests",
                "System tests"]

  HEADERS = { lines: " Lines", code_lines: "   LOC", classes: "Classes", methods: "Methods" }

  def initialize(*pairs)
    @pairs      = pairs
    @statistics = calculate_statistics
    @total      = calculate_total if pairs.length > 1
  end

  def to_s
    print_header
    @pairs.each { |pair| print_line(pair.first, @statistics[pair.first]) }
    print_splitter

    if @total
      print_line("Total", @total)
      print_splitter
    end

    print_code_test_stats
  end

  private
    def calculate_statistics
      Hash[@pairs.map { |pair| [pair.first, calculate_directory_statistics(pair.last)] }]
    end

{'fraction_non_alphanumeric': 0.09757281553398059, 'fraction_numerical': 0.000970873786407767, 'mean_word_length': 2.5968586387434556, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1543090', 'n_tokens_mistral': 649, 'n_tokens_neox': 611, 'n_words': 142}