Class: CSVConverter::Converters::DateConverter
- Inherits:
-
BaseConverter
- Object
- BaseConverter
- CSVConverter::Converters::DateConverter
- Defined in:
- lib/csv_converter/converters/date_converter.rb
Overview
Converts a string into a date
Instance Attribute Summary
Attributes inherited from BaseConverter
Instance Method Summary collapse
-
#call ⇒ Date
Converts data into a Date using the format provided in the mappings.
-
#call! ⇒ Date
Converts data into a Date using the format provided in the mappings.
-
#initialize(raw_data, options = { date_format: '%m/%d/%y' }) ⇒ DateConverter
constructor
A new instance of DateConverter.
Methods inherited from BaseConverter
Constructor Details
#initialize(raw_data, options = { date_format: '%m/%d/%y' }) ⇒ DateConverter
A new instance of DateConverter.
12 13 14 15 16 |
# File 'lib/csv_converter/converters/date_converter.rb', line 12 def initialize(raw_data, = { date_format: '%m/%d/%y' }) super(raw_data, ) end |
Instance Method Details
#call ⇒ Date
Converts data into a Date using the format provided in the mappings.
20 21 22 23 24 |
# File 'lib/csv_converter/converters/date_converter.rb', line 20 def call call! rescue CSVConverter::Error nullable_object end |
#call! ⇒ Date
Converts data into a Date using the format provided in the mappings.
28 29 30 31 32 |
# File 'lib/csv_converter/converters/date_converter.rb', line 28 def call! Date.strptime(data, [:date_format]) rescue StandardError => e raise CSVConverter::Error.new(e., ) end |