Class: ShallowAttributes::Type::DateTime Abstract
- Inherits:
-
Object
- Object
- ShallowAttributes::Type::DateTime
- Defined in:
- lib/shallow_attributes/type/date_time.rb
Overview
This class is abstract.
Abstract class for typecast object to DateTime type.
Instance Method Summary collapse
-
#coerce(value, options = {}) ⇒ DateTime
Convert value to DateTime type.
Instance Method Details
#coerce(value, options = {}) ⇒ DateTime
Convert value to DateTime type
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/shallow_attributes/type/date_time.rb', line 25 def coerce(value, = {}) case value when ::DateTime then value when ::Time then ::DateTime.parse(value.to_s) else ::DateTime.parse(value) end rescue raise ShallowAttributes::Type::InvalidValueError, %(Invalid value "#{value}" for type "DateTime") end |