rexle 0.9.34 → 0.9.35
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rexle.rb +12 -5
- metadata +1 -1
data/lib/rexle.rb
CHANGED
@@ -27,6 +27,7 @@ include REXML
|
|
27
27
|
# 24-Jul-2011: Smybols are used for attribute keys instead of strings now
|
28
28
|
# 18-Jun-2011: A Rexle document can now be added to another Rexle document
|
29
29
|
# e.g. Rexle.new('<root/>').add Rexle.new "<a>123</a>"
|
30
|
+
s
|
30
31
|
module XMLhelper
|
31
32
|
|
32
33
|
def doc_print(children)
|
@@ -286,8 +287,14 @@ class Rexle
|
|
286
287
|
return_elements = []
|
287
288
|
|
288
289
|
if raw_path[0,2] == '//' then
|
290
|
+
|
291
|
+
regex = /\[(\d+)\]/
|
292
|
+
n = xpath_value[regex,1]
|
293
|
+
xpath_value.slice!(regex)
|
294
|
+
|
289
295
|
rs = scan_match(self, xpath_value).flatten.compact
|
290
|
-
return rs
|
296
|
+
return n ? rs[n.to_i-1] : rs
|
297
|
+
|
291
298
|
elsif (raw_path == '.' or raw_path == self.name) and attr_search.nil? then
|
292
299
|
return [self]
|
293
300
|
else
|
@@ -299,7 +306,6 @@ class Rexle
|
|
299
306
|
|
300
307
|
end
|
301
308
|
|
302
|
-
|
303
309
|
if return_elements.length > 0 then
|
304
310
|
|
305
311
|
if (a_path + [remaining_path]).join.empty? then
|
@@ -387,7 +393,7 @@ class Rexle
|
|
387
393
|
def attribute(key)
|
388
394
|
key = key.to_sym if key.is_a? String
|
389
395
|
@attributes[key].gsub('<','<').gsub('>','>')
|
390
|
-
end
|
396
|
+
end
|
391
397
|
|
392
398
|
def attributes() @attributes end
|
393
399
|
def children() @child_elements end
|
@@ -470,12 +476,13 @@ class Rexle
|
|
470
476
|
|
471
477
|
def format_condition(condition)
|
472
478
|
|
473
|
-
raw_items = condition[1..-1].scan(/\'[^\']*\'|\"[^\"]*\"|and|or|\d+|[!=<>]+|position\(\)|[@\w
|
479
|
+
raw_items = condition[1..-1].scan(/\'[^\']*\'|\"[^\"]*\"|and|or|\d+|[!=<>]+|position\(\)|[@\w\.\/&;]+/)
|
474
480
|
|
475
481
|
if raw_items[0][/^\d+$/] then
|
476
482
|
return raw_items[0].to_i
|
477
483
|
elsif raw_items[0] == 'position()' then
|
478
|
-
|
484
|
+
rrr = "i %s %s" % raw_items[1].gsub('<','<').gsub('>','>'), raw_items[-1]]
|
485
|
+
return rrr
|
479
486
|
else
|
480
487
|
|
481
488
|
andor_items = raw_items.map.with_index.select{|x,i| x[/\band\b|\bor\b/]}.map{|x| [x.last, x.last + 1]}.flatten
|