Class: Gorillib::Factory::TimeFactory
- Inherits:
-
ConvertingFactory
- Object
- BaseFactory
- ConvertingFactory
- Gorillib::Factory::TimeFactory
- Defined in:
- lib/gorillib/factories.rb
Constant Summary collapse
- FLAT_TIME_RE =
/\A\d{14}Z?\z/
Instance Method Summary collapse
Methods inherited from ConvertingFactory
Methods inherited from BaseFactory
blankish?, #blankish?, #initialize, native?, #receive, typename, #typename
Constructor Details
This class inherits a constructor from Gorillib::Factory::BaseFactory
Instance Method Details
#convert(obj) ⇒ Object
437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
# File 'lib/gorillib/factories.rb', line 437 def convert(obj) case obj when FLAT_TIME_RE then product.utc(obj[0..3].to_i, obj[4..5].to_i, obj[6..7].to_i, obj[8..9].to_i, obj[10..11].to_i, obj[12..13].to_i) when Time then obj.getutc when Date then product.utc(obj.year, obj.month, obj.day) when String then product.parse(obj).utc when Numeric then product.at(obj) else mismatched!(obj) end rescue ArgumentError => err raise if err.is_a?(TypeMismatchError) warn "Cannot parse time #{obj}: #{err}" return nil end |
#native?(obj) ⇒ Boolean
436 |
# File 'lib/gorillib/factories.rb', line 436 def native?(obj) super(obj) && obj.utc_offset == 0 ; end |