Class: Stockboy::Translations::Date
- Inherits:
-
Stockboy::Translator
- Object
- Stockboy::Translator
- Stockboy::Translations::Date
- Defined in:
- lib/stockboy/translations/date.rb
Overview
Convert ISO-8601 and other recognized date-like strings to Date
Job template DSL
Registered as :date
. Use with:
attributes do
check_in as: :date
end
Defined Under Namespace
Modules: PatternMatching
Instance Attribute Summary
Attributes inherited from Stockboy::Translator
Instance Method Summary collapse
Methods inherited from Stockboy::Translator
Constructor Details
This class inherits a constructor from Stockboy::Translator
Instance Method Details
#translate(context) ⇒ Date
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/stockboy/translations/date.rb', line 28 def translate(context) value = field_value(context, field_key) return nil if value.blank? case value when ::String then parse_date(value.strip) when ::Time, ::DateTime then ::Date.new(value.year, value.month, value.day) when ::Date then value else nil end end |