Class: Monolens::Coerce::Date
- Inherits:
-
Object
- Object
- Monolens::Coerce::Date
- Includes:
- Lens
- Defined in:
- lib/monolens/coerce/date.rb
Instance Attribute Summary
Attributes included from Lens
Instance Method Summary collapse
Methods included from Lens
#fetch_on, #initialize, #is_array!, #is_enumerable!, #is_hash!, #is_string!, #option
Instance Method Details
#call(arg, *rest) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/monolens/coerce/date.rb', line 8 def call(arg, *rest) is_string!(arg) date, first_error = nil, nil @options[:formats].each do |format| begin return date = ::Date.strptime(arg, format) rescue ArgumentError => ex first_error ||= ex rescue ::Date::Error => ex first_error ||= ex end end raise Monolens::LensError, first_error. end |