cwyckoff-babel_icious 0.0.2 → 0.0.3

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.
@@ -1,6 +1,18 @@
1
1
  module Babelicious
2
2
 
3
3
  class HashMap
4
+
5
+ class << self
6
+
7
+ def initial_target
8
+ {}
9
+ end
10
+
11
+ def filter_source(source)
12
+ source
13
+ end
14
+
15
+ end
4
16
 
5
17
  def initialize(path_translator)
6
18
  @path_translator = path_translator
@@ -33,7 +33,7 @@ module Babelicious
33
33
  def translate(key=nil, source=nil)
34
34
  raise MapperError, "No target mapper exists for key #{key}" unless mappings.has_key?(key)
35
35
 
36
- mappings[key].map(source)
36
+ mappings[key].translate(source)
37
37
  end
38
38
 
39
39
  private
@@ -16,10 +16,13 @@ module Babelicious
16
16
  @direction = dir
17
17
  end
18
18
 
19
- def map(source)
20
- target = initial_target
19
+ def translate(source)
20
+ target = nil
21
21
  @mappings.each do |source_element, target_element|
22
- source_value = source_element.value_from(source)
22
+ target = target_element.class.initial_target if target.nil?
23
+ filtered_source = source_element.class.filter_source(source) if filtered_source.nil?
24
+
25
+ source_value = source_element.value_from(filtered_source)
23
26
  target_element.map_from(target, source_value)
24
27
  end
25
28
  target
@@ -34,20 +37,6 @@ module Babelicious
34
37
  def reset
35
38
  @mappings, @direction = [], nil
36
39
  end
37
-
38
-
39
- private
40
-
41
- def initial_target
42
- raise TargetMapperError, "please set @direction (e.g., target_mapper.direction = {:from => :xml, :to => :hash}" unless @direction
43
-
44
- case @direction[:to]
45
- when :xml
46
- XML::Document.new()
47
- when :hash
48
- {}
49
- end
50
- end
51
40
 
52
41
  end
53
42
  end
@@ -4,6 +4,18 @@ module Babelicious
4
4
 
5
5
  class XmlMap
6
6
 
7
+ class << self
8
+
9
+ def initial_target
10
+ XML::Document.new
11
+ end
12
+
13
+ def filter_source(source)
14
+ XML::Document.string(source)
15
+ end
16
+
17
+ end
18
+
7
19
  def initialize(path_translator)
8
20
  @path_translator = path_translator
9
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cwyckoff-babel_icious
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wyckoff
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-13 00:00:00 -07:00
12
+ date: 2009-04-14 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency