Class: Necromancer::ArrayConverters::ArrayToNumericArrayConverter

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

Overview

An object that converts an array to an array with numeric values

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 an array to an array of numeric values

Examples:

converter.call(["1", "2.3", "3.0])  # => [1, 2.3, 3.0]

Parameters:

  • value (Array)

    the value to convert



128
129
130
131
132
# File 'lib/necromancer/converters/array.rb', line 128

def call(value, strict: config.strict)
  num_converter = NumericConverters::StringToNumericConverter.new(:string,
                                                                  :numeric)
  value.map { |val| num_converter.(val, strict: strict) }
end