rexle 0.9.63 → 0.9.64
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 +30 -10
- metadata +2 -2
data/lib/rexle.rb
CHANGED
@@ -10,6 +10,8 @@ require 'cgi'
|
|
10
10
|
include REXML
|
11
11
|
|
12
12
|
# modifications:
|
13
|
+
# 06-Nov-2012: additional xpath predicate now implemented e.g.
|
14
|
+
# fun/. > 200 => [false, false, true, true]
|
13
15
|
# 21-Oct-2012: xpath predicate now implemented e.g. fun/@id='4' => true
|
14
16
|
# 20-Oct-2012: feature: added Rexle::Element#texts which is the equivalent
|
15
17
|
# of REXML::Element#texts
|
@@ -88,7 +90,7 @@ module XMLhelper
|
|
88
90
|
def pretty_print(nodes, indent='0')
|
89
91
|
indent = indent.to_i
|
90
92
|
|
91
|
-
nodes.select(){|x| x.is_a? Rexle::Element or x.strip.length > 0}
|
93
|
+
nodes.select(){|x| x.is_a? Rexle::Element or (x.is_a? String and x.strip.length > 0)}
|
92
94
|
.map.with_index do |x, i|
|
93
95
|
|
94
96
|
if x.is_a? Rexle::Element then
|
@@ -220,7 +222,15 @@ class Rexle
|
|
220
222
|
# Array: proc {|x| x.flatten.compact},
|
221
223
|
if (fn_match and fn_match.captures.first[/^(attribute|@)/]) or fn_match.nil? then
|
222
224
|
procs = {
|
223
|
-
Array: proc {|x| block_given? ? x : x.flatten.uniq },
|
225
|
+
#jr061012 Array: proc {|x| block_given? ? x : x.flatten.uniq },
|
226
|
+
Array: proc { |x|
|
227
|
+
if block_given? then
|
228
|
+
x.flatten(1)
|
229
|
+
else
|
230
|
+
rs = x.flatten
|
231
|
+
rs.any?{|x| x == true or x == false} ? rs : rs.uniq(&:object_id)
|
232
|
+
end
|
233
|
+
},
|
224
234
|
String: proc {|x| x},
|
225
235
|
Hash: proc {|x| x},
|
226
236
|
TrueClass: proc{|x| x},
|
@@ -231,9 +241,9 @@ class Rexle
|
|
231
241
|
raw_results = path.split('|').map do |xp|
|
232
242
|
query_xpath(xp, bucket, &blk)
|
233
243
|
end
|
234
|
-
|
235
|
-
results = raw_results
|
236
|
-
|
244
|
+
|
245
|
+
results = raw_results
|
246
|
+
|
237
247
|
procs[results.class.to_s.to_sym].call(results) if results
|
238
248
|
|
239
249
|
else
|
@@ -295,10 +305,12 @@ class Rexle
|
|
295
305
|
|
296
306
|
elmnt_path = s[/^([\w:\*]+\[[^\]]+\])|[\/]+{,2}[^\/]+/]
|
297
307
|
element_part = elmnt_path[/(^@?[^\[]+)?/,1] if elmnt_path
|
298
|
-
|
308
|
+
|
299
309
|
if element_part then
|
300
|
-
|
310
|
+
|
311
|
+
unless element_part[/^(@|[@\.\w]+[\s=])/] then
|
301
312
|
element_name = element_part[/^[\w:\*\.]+/]
|
313
|
+
|
302
314
|
else
|
303
315
|
if xpath_value[/^\[/] then
|
304
316
|
condition = xpath_value
|
@@ -565,7 +577,6 @@ class Rexle
|
|
565
577
|
else
|
566
578
|
|
567
579
|
andor_items = raw_items.map.with_index.select{|x,i| x[/\band\b|\bor\b/]}.map{|x| [x.last, x.last + 1]}.flatten
|
568
|
-
|
569
580
|
indices = [0] + andor_items + [raw_items.length]
|
570
581
|
|
571
582
|
if raw_items[0][0] == '@' then
|
@@ -587,6 +598,7 @@ class Rexle
|
|
587
598
|
else
|
588
599
|
|
589
600
|
cons_items = indices.each_cons(2).map{|x,y| raw_items.slice(x...y)}
|
601
|
+
|
590
602
|
items = cons_items.map do |x|
|
591
603
|
|
592
604
|
if x.length >= 3 then
|
@@ -664,6 +676,7 @@ class Rexle
|
|
664
676
|
end
|
665
677
|
|
666
678
|
def attribute_search(attr_search, e, h, i=nil, &blk)
|
679
|
+
|
667
680
|
if attr_search.is_a? Fixnum then
|
668
681
|
block_given? ? blk.call(e) : e if i == attr_search
|
669
682
|
elsif attr_search[/i\s[<>\=]\s\d+/] and eval(attr_search) then
|
@@ -674,8 +687,15 @@ class Rexle
|
|
674
687
|
block_given? ? blk.call(e) : e
|
675
688
|
elsif attr_search[/^\(name ==/] and eval(attr_search)
|
676
689
|
block_given? ? blk.call(e) : e
|
677
|
-
elsif attr_search[/^e\.value/]
|
678
|
-
|
690
|
+
elsif attr_search[/^e\.value/]
|
691
|
+
|
692
|
+
v = attr_search[/[^\s]+$/]
|
693
|
+
duck_type = %w(to_f to_i to_s).detect {|x| v == v.send(x).to_s}
|
694
|
+
attr_search.sub!(/^e.value/,'e.value.' + duck_type)
|
695
|
+
|
696
|
+
if eval(attr_search) then
|
697
|
+
block_given? ? blk.call(e) : e
|
698
|
+
end
|
679
699
|
elsif attr_search[/^e\.xpath/] and eval(attr_search)
|
680
700
|
block_given? ? blk.call(e) : e
|
681
701
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: rexle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.9.
|
5
|
+
version: 0.9.64
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James Robertson
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-11-06 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rexleparser
|