Class: Stockboy::Translations::Time

Inherits:
Stockboy::Translator show all
Defined in:
lib/stockboy/translations/time.rb

Overview

Convert ISO-8601 and other recognized time-like strings to Time

Uses ActiveSupport::TimeWithZone if available.

Job template DSL

Registered as :time. Use with:

attributes do
  arriving as: :time
end

Examples:

time = Stockboy::Translator::Time.new

record.arriving = "2012-01-01 12:34:56 UTC"
time.translate(record, :arriving) # => #<Time 2012-01-01 12:34:56>

Instance Attribute Summary

Attributes inherited from Stockboy::Translator

#field_key

Instance Method Summary collapse

Methods inherited from Stockboy::Translator

#call, #initialize, #inspect

Constructor Details

This class inherits a constructor from Stockboy::Translator

Instance Method Details

#translate(context) ⇒ Time

Returns:



27
28
29
30
31
32
# File 'lib/stockboy/translations/time.rb', line 27

def translate(context)
  value = field_value(context, field_key)
  return nil if (value).blank?

  clock.parse(value).to_time
end