rexle 0.2.12 → 0.2.13
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/rexle.rb +17 -14
- metadata +1 -1
data/lib/rexle.rb
CHANGED
@@ -62,29 +62,29 @@ class Rexle
|
|
62
62
|
|
63
63
|
return scan_match(self, element_name, attr_search, condition, rlist) if xpath_value[0,2] == '//'
|
64
64
|
|
65
|
-
return_elements = @child_lookup.map.with_index.select
|
66
|
-
|
65
|
+
return_elements = @child_lookup.map.with_index.select do |x|
|
67
66
|
x[0][0] == element_name or element_name == '*'
|
68
|
-
|
67
|
+
end
|
69
68
|
|
70
69
|
if return_elements.length > 0 then
|
71
70
|
|
72
71
|
if a.empty? then
|
73
72
|
rlist = return_elements.map.with_index {|x,i| filter(x, i+1, attr_search)}
|
74
73
|
else
|
75
|
-
|
76
|
-
return_elements.map.with_index do |x,i|
|
77
|
-
rtn_element = filter(x, i+1, attr_search){|e| r = e.xpath(a.join('/')
|
74
|
+
|
75
|
+
rlist << return_elements.map.with_index do |x,i|
|
76
|
+
rtn_element = filter(x, i+1, attr_search){|e| r = e.xpath(a.join('/')); r || e }
|
78
77
|
next unless rtn_element
|
79
78
|
|
80
79
|
if rtn_element.is_a? Array then
|
81
|
-
|
80
|
+
rtn_element.flatten
|
82
81
|
elsif (rtn_element.is_a? String) || not(rtn_element[0].is_a? String)
|
83
|
-
|
82
|
+
rtn_element
|
84
83
|
end
|
85
84
|
end
|
86
85
|
|
87
86
|
end
|
87
|
+
|
88
88
|
else
|
89
89
|
|
90
90
|
# strip off the 1st element from the XPath
|
@@ -175,7 +175,6 @@ class Rexle
|
|
175
175
|
end # -- end of element --
|
176
176
|
|
177
177
|
def root() @doc end
|
178
|
-
|
179
178
|
def xml()
|
180
179
|
body = scan_print(self.root.children).join
|
181
180
|
"<%s>%s</%s>" % [self.root.name, body, self.root.name]
|
@@ -204,7 +203,7 @@ class Rexle
|
|
204
203
|
value = raw_values
|
205
204
|
|
206
205
|
if raw_values.length > 0 then
|
207
|
-
match_found = raw_values.match(/(.*)>([^>]
|
206
|
+
match_found = raw_values.match(/(.*)>([^>]*$)/)
|
208
207
|
if match_found then
|
209
208
|
raw_attributes, value = match_found.captures
|
210
209
|
attributes = raw_attributes.split(/\s/).inject({}) do |r, x|
|
@@ -226,6 +225,9 @@ class Rexle
|
|
226
225
|
r = scan_element(a)
|
227
226
|
element.add_element(r) if r
|
228
227
|
|
228
|
+
# capture siblings
|
229
|
+
#a.slice!(0, name.length + 3) if a[0, name.length + 3].join == "</%s>" % name
|
230
|
+
|
229
231
|
(r = scan_element(a); element.add_element r if r) until (a[0, name.length + 3].join == "</%s>" % [name]) or a.length < 2
|
230
232
|
else
|
231
233
|
#check for its end tag
|
@@ -241,15 +243,16 @@ class Rexle
|
|
241
243
|
end
|
242
244
|
|
243
245
|
def scan_print(nodes)
|
244
|
-
|
245
|
-
nodes.
|
246
|
-
out
|
246
|
+
|
247
|
+
nodes.map do |x|
|
248
|
+
out = ["<%s>" % x.name]
|
247
249
|
out << scan_print(x.children)
|
248
250
|
out << "</%s>" % x.name
|
249
251
|
end
|
250
|
-
|
252
|
+
|
251
253
|
end
|
252
254
|
|
253
255
|
def count(path) @doc.xpath(path).flatten.compact.length end
|
254
256
|
|
255
257
|
end
|
258
|
+
|