<commit_before>module Atlas
  module ActiveDocument
    class ResidencesValidator < ActiveModel::Validator
      def validate(record)
        sum_of_residences = record.number_of_old_residences +
                            record.number_of_new_residences

        unless record.number_of_residences.round == sum_of_residences.round
          record.errors.add(:number_of_residences,
            "Number of old residences (#{ record.number_of_old_residences}) "\
            "and number of new residences (#{ record.number_of_new_residences }) "\
            "don't add up to the total number of residences "\
            "(#{ record.number_of_residences })."
          )
        end
      end
    end
  end
end<commit_msg>Don't validate the residences if the number of new or old residences aren't both present<commit_after>module Atlas
  module ActiveDocument
    class ResidencesValidator < ActiveModel::Validator
      def validate(record)
        return if record.number_of_old_residences.nil? ||
                  record.number_of_new_residences.nil?

        sum_of_residences = record.number_of_old_residences +
                            record.number_of_new_residences

        unless record.number_of_residences.round == sum_of_residences.round
          record.errors.add(:number_of_residences,
            "Number of old residences (#{ record.number_of_old_residences}) "\
            "and number of new residences (#{ record.number_of_new_residences }) "\
            "don't add up to the total number of residences "\
            "(#{ record.number_of_residences })."
          )
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07217125382262997, 'fraction_numerical': 0.0, 'mean_word_length': 2.429769392033543, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4223202', 'n_tokens_mistral': 472, 'n_tokens_neox': 441, 'n_words': 101}