class ActiveAttr::Typecasting::DateTypecaster

Typecasts an Object to a Date

@example Usage

DateTypecaster.new.call("2012-01-01") #=> Sun, 01 Jan 2012

@since 0.5.0

Public Instance Methods

call(value) click to toggle source

Typecasts an object to a Date

Attempts to convert using to_date.

@example Typecast a String

typecaster.call("2012-01-01") #=> Sun, 01 Jan 2012

@param [Object, to_date] value The object to typecast

@return [Date, nil] The result of typecasting

@since 0.5.0

# File lib/active_attr/typecasting/date_typecaster.rb, line 25
def call(value)
  value.to_date if value.respond_to? :to_date
rescue NoMethodError, ArgumentError
end