Class: Extant::Coercers::Time

Inherits:
Base
  • Object
show all
Defined in:
lib/extant/coercers/time.rb

Constant Summary

Constants inherited from Base

Base::UncoercedValue

Instance Method Summary collapse

Methods inherited from Base

#coerced?, coercer_name, #initialize

Constructor Details

This class inherits a constructor from Extant::Coercers::Base

Instance Method Details

#coerceObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/extant/coercers/time.rb', line 5

def coerce
  if value.is_a?(::Time)
    self.coerced = true
    return value
  end

  result = ::Time.parse(value.to_s)
  self.coerced = true
  result
rescue ArgumentError
  UncoercedValue
end