<commit_before>class Orphan < ActiveRecord::Base
  validates :name, presence: true
  validates :father_name, presence: true
  validates :father_is_martyr, inclusion: {in: [true, false] }, exclusion: { in: [nil]}
  validates :father_date_of_death, presence: true, date_not_in_future: true
  validates :mother_name, presence: true
  validates :mother_alive, inclusion: {in: [true, false] }, exclusion: { in: [nil]}
  validates :date_of_birth, presence: true, date_not_in_future: true
  validates :gender, presence: true, inclusion: {in: %w(Male Female) } # TODO: DRY list of allowed values
  validates :contact_number, presence: true
  validates :sponsored_by_another_org, inclusion: {in: [true, false] }, exclusion: { in: [nil]}
  validates :minor_siblings_count, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
  validates :original_address, presence: true
  validates :current_address, presence: true
  validates :orphan_status, presence: true
  validate :orphans_dob_within_gestation_of_fathers_death

  has_one :original_address, foreign_key: 'orphan_original_address_id', class_name: 'Address'
  has_one :current_address, foreign_key: 'orphan_current_address_id', class_name: 'Address'

  belongs_to :orphan_status

  accepts_nested_attributes_for :current_address, allow_destroy: true
  accepts_nested_attributes_for :original_address, allow_destroy: true

  def full_name
    [name, father_name].join(' ')
  end

  def orphans_dob_within_gestation_of_fathers_death
    # gestation is considered vaild if within 1 year of a fathers death
    return unless valid_date?(father_date_of_death) && valid_date?(date_of_birth)
    if (father_date_of_death + 1.year) < date_of_birth
      errors.add(:date_of_birth, "date of birth must be within the gestation period of fathers death")
    end
  end
 
  private

  def valid_date? date
    begin 
      Date.parse(date.to_s)
    rescue ArgumentError
      return false
    end
  end

end<commit_msg>changed validation method name for improved clarity<commit_after>class Orphan < ActiveRecord::Base
  validates :name, presence: true
  validates :father_name, presence: true
  validates :father_is_martyr, inclusion: {in: [true, false] }, exclusion: { in: [nil]}
  validates :father_date_of_death, presence: true, date_not_in_future: true
  validates :mother_name, presence: true
  validates :mother_alive, inclusion: {in: [true, false] }, exclusion: { in: [nil]}
  validates :date_of_birth, presence: true, date_not_in_future: true
  validates :gender, presence: true, inclusion: {in: %w(Male Female) } # TODO: DRY list of allowed values
  validates :contact_number, presence: true
  validates :sponsored_by_another_org, inclusion: {in: [true, false] }, exclusion: { in: [nil]}
  validates :minor_siblings_count, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
  validates :original_address, presence: true
  validates :current_address, presence: true
  validates :orphan_status, presence: true
  validate :orphans_dob_within_1yr_of_fathers_death

  has_one :original_address, foreign_key: 'orphan_original_address_id', class_name: 'Address'
  has_one :current_address, foreign_key: 'orphan_current_address_id', class_name: 'Address'

  belongs_to :orphan_status

  accepts_nested_attributes_for :current_address, allow_destroy: true
  accepts_nested_attributes_for :original_address, allow_destroy: true

  def full_name
    [name, father_name].join(' ')
  end

  def orphans_dob_within_1yr_of_fathers_death
    # gestation is considered vaild if within 1 year of a fathers death
    return unless valid_date?(father_date_of_death) && valid_date?(date_of_birth)
    if (father_date_of_death + 1.year) < date_of_birth
      errors.add(:date_of_birth, "date of birth must be within the gestation period of fathers death")
    end
  end
 
  private

  def valid_date? date
    begin 
      Date.parse(date.to_s)
    rescue ArgumentError
      return false
    end
  end

end
{'fraction_non_alphanumeric': 0.08429503261414953, 'fraction_numerical': 0.002007024586051179, 'mean_word_length': 5.441033925686591, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5589677', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1272, 'n_words': 349}