Class: Necromancer::HashConverters::StringToNumericHashConverter

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

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 string value to hash with numeric values

Examples:

converter.call("a:1 b:2.0 c:3")
# => {a: 1, b: 2.0, c: 3}


79
80
81
82
83
84
# File 'lib/necromancer/converters/hash.rb', line 79

def call(value, strict: config.strict)
  num_converter = NumericConverters::StringToNumericConverter.new(:string,
                                                                  :numeric)
  hash_converter = StringToHashConverter.new(:string, :hash)
  hash_converter.(value, strict: strict, value_converter: num_converter)
end