Class: Workable::Transformation
- Inherits:
-
Object
- Object
- Workable::Transformation
- Defined in:
- lib/workable/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.
3 4 5 |
# File 'lib/workable/transformation.rb', line 3 def initialize(mappings) @mappings = mappings || {} end |
Instance Method Details
#apply(mapping, data) ⇒ Object|nil
selects transformation strategy based on the inputs
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/workable/transformation.rb', line 12 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 |