Class: Necromancer::HashConverters::StringToFloatHashConverter

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 float values

Examples:

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


63
64
65
66
67
68
# File 'lib/necromancer/converters/hash.rb', line 63

def call(value, strict: config.strict)
  float_converter = NumericConverters::StringToFloatConverter.new(:string,
                                                                  :float)
  hash_converter = StringToHashConverter.new(:string, :hash)
  hash_converter.(value, strict: strict, value_converter: float_converter)
end