Class: Necromancer::ArrayConverters::ArrayToNumericConverter

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

#convert, #source, #target

Instance Method Summary collapse

Methods inherited from Converter

create, #fail_conversion_type, #initialize

Constructor Details

This class inherits a constructor from Necromancer::Converter

Instance Method Details

#call(value, options = {}) ⇒ 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



45
46
47
48
49
50
# File 'lib/necromancer/converters/array.rb', line 45

def call(value, options = {})
  numeric_converter = NumericConverters::StringToNumericConverter.new(:string, :numeric)
  value.reduce([]) do |acc, el|
    acc << numeric_converter.call(el, options)
  end
end