Class: Gorillib::Factory::DateFactory
- Inherits:
-
ConvertingFactory
- Object
- BaseFactory
- ConvertingFactory
- Gorillib::Factory::DateFactory
- Defined in:
- lib/gorillib/type/extended.rb
Constant Summary collapse
- FLAT_DATE_RE =
/\A\d{8}Z?\z/
Instance Method Summary collapse
Methods inherited from ConvertingFactory
Methods inherited from BaseFactory
#blankish?, blankish?, #initialize, #native?, native?, #receive, typename, #typename
Constructor Details
This class inherits a constructor from Gorillib::Factory::BaseFactory
Instance Method Details
#convert(obj) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gorillib/type/extended.rb', line 29 def convert(obj) case obj when FLAT_DATE_RE then product.new(obj[0..3].to_i, obj[4..5].to_i, obj[6..7].to_i) when Time then Date.new(obj.year, obj.month, obj.day) when String then Date.parse(obj) else mismatched!(obj) end rescue ArgumentError => err raise if err.is_a?(TypeMismatchError) warn "Cannot parse time #{obj}: #{err}" return nil end |