class DataMapper::Property::Legacy::DateString
Public Instance Methods
dump(value)
click to toggle source
Dumps a date to a string.
@param [Date, nil] value
The date to dump.
@return [String, nil]
The date string.
# 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)
click to toggle source
Parses a date string.
@param [String] value
The date string.
@return [Date, nil]
The parsed date.
# 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)
click to toggle source
Typecasts a date.
@param [Date, Time, String, nil] value
The date to typecast.
@return [Date, nil]
The typecasted date.
# 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