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