Class: Spine::Transform::Transformer
- Inherits:
-
Object
- Object
- Spine::Transform::Transformer
- Extended by:
- Definition
- Defined in:
- lib/spine/transform/transformer.rb
Instance Attribute Summary collapse
-
#mapping ⇒ Object
readonly
Returns the value of attribute mapping.
Instance Method Summary collapse
-
#initialize(dsl) ⇒ Transformer
constructor
A new instance of Transformer.
- #transform(source, destination = {}) ⇒ Object
Methods included from Definition
Constructor Details
#initialize(dsl) ⇒ Transformer
Returns a new instance of Transformer.
8 9 10 11 |
# File 'lib/spine/transform/transformer.rb', line 8 def initialize(dsl) @mapping = Mapping.new(dsl) @mapping.parse end |
Instance Attribute Details
#mapping ⇒ Object (readonly)
Returns the value of attribute mapping.
6 7 8 |
# File 'lib/spine/transform/transformer.rb', line 6 def mapping @mapping end |
Instance Method Details
#transform(source, destination = {}) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/spine/transform/transformer.rb', line 13 def transform(source, destination = {}) source.reduce(destination) do |result, (key, value)| mapping.for(key).execute(result, value) result end end |