Class: Necromancer::NumericConverters::StringToFloatConverter

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

Overview

An object that converts a String to a Float

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 to float value

Examples:

converter.call("1.2") # => 1.2


49
50
51
52
53
# File 'lib/necromancer/converters/numeric.rb', line 49

def call(value, strict: config.strict)
  Float(value)
rescue StandardError
  strict ? raise_conversion_type(value) : value.to_f
end