cwyckoff-babel_icious 0.0.4 → 0.0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/babel_icious/target_mapper.rb +6 -6
- data/lib/babel_icious/xml_map.rb +1 -1
- metadata +1 -1
@@ -3,11 +3,10 @@ class TargetMapperError < Exception; end
|
|
3
3
|
module Babelicious
|
4
4
|
|
5
5
|
class TargetMapper
|
6
|
-
attr_reader :mappings, :direction
|
6
|
+
attr_reader :mappings, :direction
|
7
7
|
|
8
8
|
def initialize
|
9
9
|
@mappings = []
|
10
|
-
@target = nil
|
11
10
|
end
|
12
11
|
|
13
12
|
def direction=(dir)
|
@@ -18,26 +17,27 @@ module Babelicious
|
|
18
17
|
end
|
19
18
|
|
20
19
|
def translate(source)
|
20
|
+
target = nil
|
21
21
|
@mappings.each do |source_element, target_element|
|
22
|
+
target = target_element.class.initial_target if target.nil?
|
22
23
|
filtered_source = source_element.class.filter_source(source) if filtered_source.nil?
|
23
24
|
|
24
25
|
source_value = source_element.value_from(filtered_source)
|
25
|
-
target_element.map_from(
|
26
|
+
target_element.map_from(target, source_value)
|
26
27
|
end
|
27
|
-
|
28
|
+
target
|
28
29
|
end
|
29
30
|
|
30
31
|
def register_mapping(opts={})
|
31
32
|
raise TargetMapperError, "Both :from and :to keys must be set (e.g., {:from => \"foo/bar\", :to => \"bar/foo\")" unless (opts[:from] && opts[:to])
|
32
33
|
target = MapFactory.target(@direction, opts)
|
33
34
|
source = MapFactory.source(@direction, opts)
|
34
|
-
@target = target.class.initial_target if @target.nil?
|
35
35
|
|
36
36
|
@mappings << [source, target]
|
37
37
|
end
|
38
38
|
|
39
39
|
def reset
|
40
|
-
@mappings, @direction
|
40
|
+
@mappings, @direction = [], nil
|
41
41
|
end
|
42
42
|
|
43
43
|
end
|
data/lib/babel_icious/xml_map.rb
CHANGED