Class: DataMaps::Converter::ForEach

Inherits:
Base show all
Defined in:
lib/data_maps/converter/for_each.rb

Overview

Apply Converter for each entry

Since:

  • 0.3.3

Instance Attribute Summary collapse

Attributes inherited from Executable

#@option, #option

Instance Method Summary collapse

Methods inherited from Executable

#initialize, valid_collection?

Constructor Details

This class inherits a constructor from DataMaps::Executable

Instance Attribute Details

#converterObject (readonly)

Since:

  • 0.3.3



7
8
9
# File 'lib/data_maps/converter/for_each.rb', line 7

def converter
  @converter
end

Instance Method Details

#after_initializeObject

The after initialize callback

Since:

  • 0.3.3



10
11
12
# File 'lib/data_maps/converter/for_each.rb', line 10

def after_initialize
  @converter = DataMaps::Converter.create_from_map(option)
end

#execute(data) ⇒ mixed

The execute converters for each value

Parameters:

  • data (mixed)

Returns:

  • (mixed)

    mutated data

Since:

  • 0.3.3



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/data_maps/converter/for_each.rb', line 18

def execute(data)
  case data
    when Array
      data.map do |value|
        converter.reduce(value) do |value, converter|
          converter.execute(value)
        end
      end
    else data
  end
end