Class: Sheetah::Types::Scalars::DateStringCast
- Inherits:
-
Object
- Object
- Sheetah::Types::Scalars::DateStringCast
- Defined in:
- lib/sheetah/types/scalars/date_string_cast.rb
Instance Method Summary collapse
- #call(value, messenger) ⇒ Object
-
#initialize(date_fmt: DATE_FMT, accept_date: true) ⇒ DateStringCast
constructor
A new instance of DateStringCast.
Constructor Details
#initialize(date_fmt: DATE_FMT, accept_date: true) ⇒ DateStringCast
Returns a new instance of DateStringCast.
15 16 17 18 |
# File 'lib/sheetah/types/scalars/date_string_cast.rb', line 15 def initialize(date_fmt: DATE_FMT, accept_date: true, **) @date_fmt = date_fmt @accept_date = accept_date end |
Instance Method Details
#call(value, messenger) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sheetah/types/scalars/date_string_cast.rb', line 20 def call(value, messenger) case value when ::Date return value if @accept_date when ::String date = parse_date_string(value) return date if date end messenger.error("must_be_date", format: @date_fmt) throw :failure end |