Class: Validation::Rule::Birthday
- Inherits:
-
Object
- Object
- Validation::Rule::Birthday
- Defined in:
- lib/diaspora_federation/validators/rules/birthday.rb
Overview
Birthday validation rule
Valid is:
-
nil or an empty
String
-
a
Date
object -
a
String
with the format “yyyy-mm-dd” and is a validDate
, example: 2015-07-25
Instance Method Summary collapse
-
#error_key ⇒ Symbol
The error key for this rule.
-
#params ⇒ Hash
This rule has no params.
-
#valid_value?(value) ⇒ Boolean
Determines if value is a valid birthday date.
Instance Method Details
#error_key ⇒ Symbol
The error key for this rule
16 17 18 |
# File 'lib/diaspora_federation/validators/rules/birthday.rb', line 16 def error_key :birthday end |
#params ⇒ Hash
This rule has no params.
35 36 37 |
# File 'lib/diaspora_federation/validators/rules/birthday.rb', line 35 def params {} end |
#valid_value?(value) ⇒ Boolean
Determines if value is a valid birthday date.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/diaspora_federation/validators/rules/birthday.rb', line 21 def valid_value?(value) return true if value.nil? || (value.is_a?(String) && value.empty?) return true if value.is_a? Date if value.is_a?(String) && value.match?(/[0-9]{4}-[0-9]{2}-[0-9]{2}/) date_field = value.split("-").map(&:to_i) return Date.valid_civil?(date_field[0], date_field[1], date_field[2]) end false end |