Class: DataMapper::Property::Legacy::TimeString
- Inherits:
-
String
- Object
- String
- DataMapper::Property::Legacy::TimeString
- Defined in:
- lib/dm-core/property/legacy/time_string.rb
Instance Method Summary collapse
-
#dump(value) ⇒ String?
Dumps a time to a string.
-
#load(value) ⇒ Time?
Parses a time string.
-
#typecast(value) ⇒ Time?
Typecasts a time.
Instance Method Details
#dump(value) ⇒ String?
Dumps a time to a string.
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/dm-core/property/legacy/time_string.rb', line 52 def dump(value) case value when ::Time value.to_s when ::Date value.to_time.to_s when nil nil else value.to_s end end |
#load(value) ⇒ Time?
Parses a time string.
20 21 22 |
# File 'lib/dm-core/property/legacy/time_string.rb', line 20 def load(value) ::Time.parse(value) unless (value.nil? || value.empty?) end |
#typecast(value) ⇒ Time?
Typecasts a time.
33 34 35 36 37 38 39 40 41 |
# File 'lib/dm-core/property/legacy/time_string.rb', line 33 def typecast(value) if value.kind_of?(::Time) value elsif value.kind_of?(::Date) value.to_time elsif value.kind_of?(::String) ::Time.parse(value) unless value.empty? end end |