class DataMapper::Property::Date

Public Instance Methods

typecast_hash_to_date(value) click to toggle source

Creates a Date instance from a Hash with keys :year, :month, :day

@param [Hash, to_mash] value

value to be typecast

@return [Date]

Date constructed from hash

@api private

# File lib/dm-core/property/date.rb, line 40
def typecast_hash_to_date(value)
  ::Date.new(*extract_time(value)[0, 3])
end
typecast_to_primitive(value) click to toggle source

Typecasts an arbitrary value to a Date Handles both Hashes and Date instances.

@param [Hash, to_mash, to_s] value

value to be typecast

@return [Date]

Date constructed from value

@api private

# File lib/dm-core/property/date.rb, line 19
def typecast_to_primitive(value)
  if value.respond_to?(:to_date)
    value.to_date
  elsif value.is_a?(::Hash) || value.respond_to?(:to_mash)
    typecast_hash_to_date(value)
  else
    ::Date.parse(value.to_s)
  end
rescue ArgumentError
  value
end