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