mirror of
https://github.com/internetee/registry.git
synced 2025-07-20 09:46:09 +02:00
refactored contact birth date validator
This commit is contained in:
parent
e345abc2fc
commit
68b9ff0c71
1 changed files with 8 additions and 5 deletions
|
@ -8,11 +8,7 @@ class Contact::Ident::BirthDateValidator < ActiveModel::Validator
|
||||||
def birth_date_wrong?(record)
|
def birth_date_wrong?(record)
|
||||||
return unless record.birthday?
|
return unless record.birthday?
|
||||||
|
|
||||||
begin
|
return true if birth_date_format_wrong?(record.code)
|
||||||
Date.parse(record.code)
|
|
||||||
rescue ArgumentError
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
contact_ident_date = Date.parse(record.code)
|
contact_ident_date = Date.parse(record.code)
|
||||||
date_from = Time.zone.today - 150.years
|
date_from = Time.zone.today - 150.years
|
||||||
|
@ -22,4 +18,11 @@ class Contact::Ident::BirthDateValidator < ActiveModel::Validator
|
||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def birth_date_format_wrong?(date)
|
||||||
|
Date.parse(date)
|
||||||
|
false
|
||||||
|
rescue ArgumentError
|
||||||
|
true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue