Class: MdsBirthdateValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/mds_birthdate_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



3
4
5
6
7
8
9
# File 'app/validators/mds_birthdate_validator.rb', line 3

def validate_each(record, attribute, value)
  return true if record.send("clean_#{attribute}").blank?
  # return true if value.blank? || Resident.missing_attribute_values.include?(value)
  record.errors[attribute] << "Invalid birth date entered in #{attribute}. Birth date may contain only numbers." and return if value =~ /\D/
  record.errors[attribute] << "Invalid birth date entered in #{attribute}. Birth date must be formatted as YYYYMMDD, YYYYMM or YYYY." and return unless birthdate_correct_length?(value)
  record.errors[attribute] << "Invalid birth date entered in #{attribute}. Birth date is not valid." unless birthdate_ymd_valid?(value)
end