<commit_before>require 'rubygems/comparator/base'

class Gem::Comparator
  class SpecComparator
    include Gem::Comparator::Base

    ##
    # Compares common fields in spec

    def compare(specs, report, options = {})
      info 'Checking spec parameters...'

      filter_params(SPEC_PARAMS, options[:param]).each do |param|
        values = []
        specs.each do |s|
          if s.respond_to? :"#{param}"
            values << s.send(:"#{param}")
          else
            warn "#{s.full_name} does not respond to #{param}, skipping check"
          end
        end

        # Are values the same?
        if values.count(values[0]) == values.size
          report[param] << "#{SUCCESS} #{param}" if options[:log_all]
        else
          report[param].set_header "#{FAIL} #{param}:"
          values.each_with_index do |value, index|
            report[param] << "#{Rainbow(specs[index].version).blue}: #{value}"
          end
        end
      end
      report
    end

  end
end
<commit_msg>Refactor spec comparison<commit_after>require 'rubygems/comparator/base'

class Gem::Comparator
  class SpecComparator
    include Gem::Comparator::Base

    ##
    # Compares common fields in spec

    def compare(specs, report, options = {})
      info 'Checking spec parameters...'

      filter_params(SPEC_PARAMS, options[:param]).each do |param|
        values = values_from_specs(param, specs)

        # Are values the same?
        if same_values? values
          report[param] << "#{SUCCESS} #{param}" if options[:log_all]
        else
          report[param].set_header "#{FAIL} #{param}:"
          values.each_with_index do |value, index|
            report[param] << \
              "#{Rainbow(specs[index].version).blue}: #{value}"
          end
        end
      end
      report
    end

    private

      def values_from_specs(param, specs)
	values = []
        specs.each do |s|
          if s.respond_to? :"#{param}"
            values << s.send(:"#{param}")
          else
            warn "#{s.full_name} does not respond to " +
		 "#{param}, skipping check"
          end
        end
	values
      end

      def same_values?(values)
        values.count(values[0]) == values.size
      end
  end
end

{'fraction_non_alphanumeric': 0.125, 'fraction_numerical': 0.0008960573476702509, 'mean_word_length': 2.114365411436541, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, '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': '1357549', 'n_tokens_mistral': 664, 'n_tokens_neox': 659, 'n_words': 168}