<commit_before>module Schema
  module Compare
    class Difference
      class Attributes
        Entry = Struct.new(
          :attr_name,
          :control_value,
          :compare_value
        )

        def entries
          @entries ||= []
        end

        def self.compare(attr_names, control_attributes, compare_attributes)
          # ...
        end

        def self.build(*args)
          compare(*args)
        end

        def difference(attr_name)
          entries.find do |entry|
            entry.attr_name == attr_name
          end
        end
        alias :[] :difference

        def add(attr_name, control_value, compare_value)
          entry = Entry.new(attr_name, control_value, compare_value)
          entries << entry
          entry
        end

        def different?(attr_name)
          entries.any? do |entry|
            entry.attr_name == attr_name
          end
        end
      end
    end
  end
end
<commit_msg>An entry is recorded for every attribute that is different<commit_after>module Schema
  module Compare
    class Difference
      class Attributes
        Entry = Struct.new(
          :attr_name,
          :control_value,
          :compare_value
        )

        def entries
          @entries ||= []
        end

        def self.compare(attr_names, control_attributes, compare_attributes)
          instance = new

          attr_names.each do |attr_name|
            entry = compare_attribute(attr_name, control_attributes, compare_attributes)
            instance.entries << entry if not entry.nil?
          end

          instance
        end

        def self.compare_attribute(attr_name, control_attributes, compare_attributes)
          control_value = control_attributes[attr_name]
          compare_value = compare_attributes[attr_name]

          if control_value == compare_value
            return nil
          end

          entry = Entry.new(
            attr_name,
            control_value,
            compare_value
          )

          entry
        end

        def self.build(*args)
          compare(*args)
        end

        def difference(attr_name)
          entries.find do |entry|
            entry.attr_name == attr_name
          end
        end
        alias :[] :difference

        def add(attr_name, control_value, compare_value)
          entry = Entry.new(attr_name, control_value, compare_value)
          entries << entry
          entry
        end

        def different?(attr_name)
          entries.any? do |entry|
            entry.attr_name == attr_name
          end
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.06300114547537228, 'fraction_numerical': 0.0, 'mean_word_length': 1.5560975609756098, 'pattern_counts': {'":': 0, '<': 9, '<?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': '1210380', 'n_tokens_mistral': 687, 'n_tokens_neox': 666, 'n_words': 170}