Class: Trackplus::Transformation
- Inherits:
-
Object
- Object
- Trackplus::Transformation
- Defined in:
- lib/trackplus/transformation.rb
Instance Method Summary collapse
-
#apply(mapping, data) ⇒ Object|nil
selects transformation strategy based on the inputs.
-
#initialize(mappings) ⇒ Transformation
constructor
A new instance of Transformation.
Constructor Details
#initialize(mappings) ⇒ Transformation
Returns a new instance of Transformation.
5 6 7 |
# File 'lib/trackplus/transformation.rb', line 5 def initialize(mappings) @mappings = mappings || {} end |
Instance Method Details
#apply(mapping, data) ⇒ Object|nil
selects transformation strategy based on the inputs
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/trackplus/transformation.rb', line 14 def apply(mapping, data) transformation = @mappings[mapping] return data unless transformation case data when nil data when Array data.map { |datas| transformation.call(datas) } else transformation.call(data) end end |