cwyckoff-babel_icious 0.0.6.2 → 0.0.6.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,18 +1,16 @@
|
|
1
1
|
require 'xml/libxml'
|
2
2
|
|
3
|
+
def new_node(name)
|
4
|
+
XML::Node.new(name)
|
5
|
+
end
|
6
|
+
|
3
7
|
module BabeliciousNodeHacks
|
4
8
|
|
5
|
-
def
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
else
|
11
|
-
a
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
9
|
+
def add(*nodes)
|
10
|
+
nodes.each { |n| self << n }
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
16
14
|
def concatenate_children(glue)
|
17
15
|
to_a.join(glue)
|
18
16
|
end
|
@@ -31,6 +29,17 @@ module BabeliciousNodeHacks
|
|
31
29
|
e
|
32
30
|
end
|
33
31
|
|
32
|
+
def to_a
|
33
|
+
self.children.reject { }
|
34
|
+
res = self.children.inject([]) do |a,b|
|
35
|
+
unless b.content.strip.empty?
|
36
|
+
a << b.content.strip
|
37
|
+
else
|
38
|
+
a
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
34
43
|
private
|
35
44
|
|
36
45
|
def child_arr(child)
|
@@ -44,10 +44,25 @@ module Babelicious
|
|
44
44
|
populate_nodes(xml_output)
|
45
45
|
map_from(xml_output, source_value)
|
46
46
|
end
|
47
|
+
|
48
|
+
rescue Exception => e
|
49
|
+
raise "There was a problem mapping the xml output for mapping '#{@path_translator.full_path}' with source value #{source_value}"
|
47
50
|
end
|
48
51
|
|
49
52
|
private
|
50
53
|
|
54
|
+
def map_source_value(source_value)
|
55
|
+
if(@customized_map)
|
56
|
+
@customized_map.call(source_value)
|
57
|
+
else
|
58
|
+
if(source_value.is_a?(String))
|
59
|
+
source_value.strip
|
60
|
+
else
|
61
|
+
source_value
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
51
66
|
def populate_nodes(xml_output)
|
52
67
|
return if @index == 0
|
53
68
|
|
@@ -74,10 +89,9 @@ module Babelicious
|
|
74
89
|
def update_node?(xml_output, source_value)
|
75
90
|
node = xml_output.find("/#{@path_translator.full_path}")
|
76
91
|
unless(node.empty?)
|
77
|
-
node[0] << source_value.strip unless source_value.nil?
|
92
|
+
node[0] << map_source_value(source_value) # source_value.strip unless source_value.nil?
|
78
93
|
return true
|
79
94
|
end
|
80
|
-
false
|
81
95
|
end
|
82
96
|
end
|
83
97
|
|
@@ -28,6 +28,10 @@ module Babelicious
|
|
28
28
|
def last
|
29
29
|
@parsed_path.last
|
30
30
|
end
|
31
|
+
|
32
|
+
def prepare_path(path)
|
33
|
+
path.gsub(/^\//, "").gsub(/\/$/, "")
|
34
|
+
end
|
31
35
|
|
32
36
|
def set_path(untranslated_path)
|
33
37
|
@full_path = untranslated_path
|
@@ -38,13 +42,13 @@ module Babelicious
|
|
38
42
|
@parsed_path.size
|
39
43
|
end
|
40
44
|
|
41
|
-
def translate(
|
42
|
-
|
45
|
+
def translate(path)
|
46
|
+
prepare_path(path).split("/")
|
43
47
|
end
|
44
48
|
|
45
|
-
def unshift(
|
46
|
-
@parsed_path.unshift(
|
47
|
-
@full_path = "#{
|
49
|
+
def unshift(path)
|
50
|
+
@parsed_path.unshift(translate(path)).flatten!
|
51
|
+
@full_path = "#{prepare_path(path)}/" << @full_path
|
48
52
|
end
|
49
53
|
|
50
54
|
end
|
data/lib/babel_icious.rb
CHANGED
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.6.
|
4
|
+
version: 0.0.6.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-06-
|
12
|
+
date: 2009-06-23 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|