Class: Necromancer::DateTimeConverters::StringToDateConverter

Inherits:
Converter
  • Object
show all
Defined in:
lib/necromancer/converters/date_time.rb

Overview

An object that converts a String to a Date

Instance Attribute Summary

Attributes inherited from Converter

#config, #convert, #source, #target

Instance Method Summary collapse

Methods inherited from Converter

create, #initialize, #raise_conversion_type

Constructor Details

This class inherits a constructor from Necromancer::Converter

Instance Method Details

#call(value, strict: config.strict) ⇒ Object

Convert a string value to a Date

Examples:

converter.call("1-1-2015")    # => "2015-01-01"
converter.call("01/01/2015")  # => "2015-01-01"
converter.call("2015-11-12")  # => "2015-11-12"
converter.call("12/11/2015")  # => "2015-11-12"


23
24
25
26
27
# File 'lib/necromancer/converters/date_time.rb', line 23

def call(value, strict: config.strict)
  Date.parse(value)
rescue StandardError
  strict ? raise_conversion_type(value) : value
end