Class: CheckMot::DateAttribute
Constant Summary
collapse
- ATTRIBUTE_REGEX =
/_date$/
- DATE_REGEX =
/^\d{4}[.-\/]\d{2}[.-\/]\d{2}$/
- TIME_REGEX =
/^\d{4}[.-\/]\d{2}[.-\/]\d{2} \d{2}:\d{2}:\d{2}$/
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Attribute
#initialize, resolve
Class Method Details
.try(name, value) ⇒ Object
9
10
11
12
13
|
# File 'lib/check_mot/date_attribute.rb', line 9
def self.try(name, value)
return unless name.to_s.match(ATTRIBUTE_REGEX)
new(value)
end
|
Instance Method Details
#value ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/check_mot/date_attribute.rb', line 15
def value
raw_val = super
case raw_val
when DATE_REGEX
Date.parse(raw_val)
when TIME_REGEX
Time.parse(raw_val)
else
raw_val
end
end
|