Class: DataMaps::Converter::ForEach
- Inherits:
-
Base
- Object
- Executable
- Base
- DataMaps::Converter::ForEach
- Defined in:
- lib/data_maps/converter/for_each.rb
Overview
Apply Converter for each entry
Instance Attribute Summary collapse
- #converter ⇒ Object readonly
Attributes inherited from Executable
Instance Method Summary collapse
-
#after_initialize ⇒ Object
The after initialize callback.
-
#execute(data) ⇒ mixed
The execute converters for each value.
Methods inherited from Executable
#initialize, valid_collection?
Constructor Details
This class inherits a constructor from DataMaps::Executable
Instance Attribute Details
#converter ⇒ Object (readonly)
7 8 9 |
# File 'lib/data_maps/converter/for_each.rb', line 7 def converter @converter end |
Instance Method Details
#after_initialize ⇒ Object
The after initialize callback
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
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 |