Class: BirthDateValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- BirthDateValidator
- Defined in:
- lib/birth_date_validator/version.rb,
lib/birth_date_validator/validator.rb
Overview
–
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
++
Constant Summary collapse
- VERSION =
'0.2.3'
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.valid?(birth_date, options) ⇒ Boolean
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/birth_date_validator/validator.rb', line 17 def valid?(birth_date, ) age_to_validate = age(birth_date) if [:at_least].present? age_to_validate >= age([:at_least]) elsif [:less_then].present? age_to_validate < age([:less_then]) elsif [:range].present? age_to_validate >= age([:range].first) && age_to_validate <= age([:range].last) end rescue false end |
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
12 13 14 |
# File 'lib/birth_date_validator/validator.rb', line 12 def validate_each(record, attribute, value) record.errors.add(attribute, .fetch(:message, :invalid)) unless BirthDateValidator.valid?(value, ) end |