Class: Spine::Transform::Transformer

Inherits:
Object
  • Object
show all
Extended by:
Definition
Defined in:
lib/spine/transform/transformer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Definition

define

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

#mappingObject (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