rexle 1.3.1 → 1.3.2
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +1 -3
- data/lib/rexle.rb +39 -16
- data.tar.gz.sig +1 -1
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c17be6210359cbed7e2a1698eed5c7b16c118ec
|
4
|
+
data.tar.gz: 1b73e55d26b5f68c66fb1cfa90703e4efff5314e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9a2e7317838895ba06abc7931eac60936a22f4b3e1a60bc9ea031d14645851393381a4b90e2215b77d90f0d1a1b16ba9daa680736dcc43373bd7f7f7ca56945
|
7
|
+
data.tar.gz: bdeee7323744309d7eec27e72c714355a51733587925b90f0b36797235b0f8e0001e2ccc92a3dc276c8ddd02ea94afbfb1e507de38ea586dffe97763231ab381
|
checksums.yaml.gz.sig
CHANGED
data/lib/rexle.rb
CHANGED
@@ -11,6 +11,8 @@ require 'cgi'
|
|
11
11
|
|
12
12
|
# modifications:
|
13
13
|
|
14
|
+
# 02-May-2015: improvement: Rexle::Element#xpath function contains() can
|
15
|
+
# now be used as a condition .e.g. b[contains(c,'10')]
|
14
16
|
# 30-Apr-2015: improvement: Rexle::Element#xpath function contains() can
|
15
17
|
# now handle string values
|
16
18
|
# feature: Implemented Rexle::Element#backtrack which
|
@@ -371,7 +373,7 @@ class Rexle
|
|
371
373
|
end
|
372
374
|
|
373
375
|
def backtrack()
|
374
|
-
BacktrackXPath.new(self)
|
376
|
+
BacktrackXPath.new(self)
|
375
377
|
end
|
376
378
|
|
377
379
|
def cdata?()
|
@@ -379,14 +381,18 @@ class Rexle
|
|
379
381
|
end
|
380
382
|
|
381
383
|
def contains(raw_args)
|
384
|
+
|
382
385
|
path, raw_val = raw_args.split(',',2)
|
383
386
|
val = raw_val.strip[/^["']?.*["']?$/]
|
384
387
|
|
385
388
|
anode = query_xpath(path)
|
386
|
-
|
389
|
+
|
390
|
+
return [false] if anode.nil? or anode.empty?
|
391
|
+
|
387
392
|
a = scan_contents(anode.first)
|
388
|
-
|
389
|
-
|
393
|
+
r = [a.grep(/#{val.sub(/^["'](.*)["']$/,'\1')}/).length > 0]
|
394
|
+
|
395
|
+
r.any?
|
390
396
|
end
|
391
397
|
|
392
398
|
def count(path)
|
@@ -537,7 +543,6 @@ class Rexle
|
|
537
543
|
|
538
544
|
def query_xpath(raw_xpath_value, rlist=[], &blk)
|
539
545
|
|
540
|
-
|
541
546
|
flag_func = false
|
542
547
|
|
543
548
|
xpath_value = raw_xpath_value.sub('child::','./')
|
@@ -555,14 +560,20 @@ class Rexle
|
|
555
560
|
|
556
561
|
remaining_path = ($').to_s
|
557
562
|
|
563
|
+
if remaining_path[/^contains\(/] then
|
564
|
+
raw_condition = raw_condition ? raw_condition + '/' + remaining_path : remaining_path
|
565
|
+
remaining_path = ''
|
566
|
+
end
|
567
|
+
|
558
568
|
r = raw_path[/^([^\/]+)(?=\/\/)/,1]
|
569
|
+
|
559
570
|
if r then
|
560
571
|
a_path = raw_path.split(/(?=\/\/)/,2)
|
561
572
|
else
|
562
573
|
a_path = raw_path.split('/',2)
|
563
574
|
end
|
564
575
|
|
565
|
-
condition = raw_condition if a_path.length <= 1
|
576
|
+
condition = raw_condition if a_path.length <= 1 #and not raw_condition[/^\[\w+\(.*\)\]$/]
|
566
577
|
|
567
578
|
if raw_path[0,2] == '//' then
|
568
579
|
s = ''
|
@@ -608,7 +619,7 @@ class Rexle
|
|
608
619
|
#element_name ||= '*'
|
609
620
|
raw_condition = '' if condition
|
610
621
|
|
611
|
-
attr_search = format_condition(condition) if condition and condition.length > 0
|
622
|
+
attr_search = format_condition(condition) if condition and condition.length > 0
|
612
623
|
attr_search2 = xpath_value[/^\[(.*)\]$/,1]
|
613
624
|
|
614
625
|
if attr_search2 then
|
@@ -645,12 +656,12 @@ class Rexle
|
|
645
656
|
if ename != '..' then
|
646
657
|
|
647
658
|
return_elements = @child_elements.map.with_index.select do |x, i|
|
648
|
-
|
659
|
+
|
649
660
|
next unless x.is_a? Rexle::Element
|
650
661
|
|
651
662
|
(x.name == ename || ename == '.') or (ename == '*')
|
652
663
|
end
|
653
|
-
|
664
|
+
|
654
665
|
if selector then
|
655
666
|
ne = return_elements.inject([]) do |r,x|
|
656
667
|
i = x.last + selector
|
@@ -680,7 +691,13 @@ class Rexle
|
|
680
691
|
|
681
692
|
if (a_path + [remaining_path]).join.empty? then
|
682
693
|
|
683
|
-
|
694
|
+
# pass in a block to the filter if it is function contains?
|
695
|
+
rlist = return_elements.map.with_index do |x,i|
|
696
|
+
r5 = filter(x, i+1, attr_search, &blk)
|
697
|
+
|
698
|
+
r5
|
699
|
+
end.compact
|
700
|
+
|
684
701
|
rlist = rlist[0] if rlist.length == 1
|
685
702
|
|
686
703
|
else
|
@@ -731,6 +748,7 @@ class Rexle
|
|
731
748
|
rlist = rlist.flatten(1) unless not(rlist.is_a? Array) or (rlist.length > 1 and rlist[0].is_a? Array)
|
732
749
|
rlist = [rlist] if rlist.is_a? Rexle::Element
|
733
750
|
rlist = (rlist.length > 0 ? true : false) if flag_func == true
|
751
|
+
|
734
752
|
rlist
|
735
753
|
end
|
736
754
|
|
@@ -990,13 +1008,17 @@ class Rexle
|
|
990
1008
|
|
991
1009
|
def format_condition(condition)
|
992
1010
|
|
993
|
-
raw_items = condition[1..-1].scan(/\'[^\']*\'|\"[^\"]*\"
|
994
|
-
|
1011
|
+
raw_items = condition[1..-1].scan(/\'[^\']*\'|\"[^\"]*\"|\
|
1012
|
+
and|or|\d+|[!=<>]+|position\(\)|contains\([^\)]+\)|[@\w\.\/&;]+/)
|
1013
|
+
|
1014
|
+
|
995
1015
|
if raw_items[0][/^\d+$/] then
|
996
1016
|
return raw_items[0].to_i
|
997
1017
|
elsif raw_items[0] == 'position()' then
|
998
1018
|
rrr = "i %s %s" % [raw_items[1].gsub('<','<').gsub('>','>'), raw_items[-1]]
|
999
1019
|
return rrr
|
1020
|
+
elsif raw_items[0][/^contains\(/]
|
1021
|
+
return raw_items[0]
|
1000
1022
|
else
|
1001
1023
|
|
1002
1024
|
andor_items = raw_items.map.with_index.select{|x,i| x[/\band\b|\bor\b/]}.map{|x| [x.last, x.last + 1]}.flatten
|
@@ -1094,7 +1116,7 @@ class Rexle
|
|
1094
1116
|
|
1095
1117
|
|
1096
1118
|
def filter(raw_element, i, attr_search, &blk)
|
1097
|
-
|
1119
|
+
|
1098
1120
|
x, index = raw_element
|
1099
1121
|
e = @child_elements[index]
|
1100
1122
|
|
@@ -1102,10 +1124,11 @@ class Rexle
|
|
1102
1124
|
name, value = e.name, e.value if e.is_a? Rexle::Element
|
1103
1125
|
|
1104
1126
|
h = x.attributes # <-- fetch the attributes
|
1105
|
-
|
1127
|
+
|
1106
1128
|
if attr_search then
|
1107
1129
|
|
1108
|
-
attribute_search(attr_search,e, h, i, &blk)
|
1130
|
+
r6 = attribute_search(attr_search,e, h, i, &blk)
|
1131
|
+
r6
|
1109
1132
|
else
|
1110
1133
|
|
1111
1134
|
block_given? ? blk.call(e) : e
|
@@ -1140,7 +1163,7 @@ class Rexle
|
|
1140
1163
|
if eval(attr_search) then
|
1141
1164
|
block_given? ? blk.call(e) : e
|
1142
1165
|
end
|
1143
|
-
elsif attr_search[/e\.xpath/] and eval(attr_search)
|
1166
|
+
elsif attr_search[/e\.xpath/] and eval(attr_search)
|
1144
1167
|
block_given? ? blk.call(e) : e
|
1145
1168
|
elsif e.element attr_search then
|
1146
1169
|
block_given? ? blk.call(e) : e
|
data.tar.gz.sig
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
������P����6��Ws��Nl3��uj���e,d>8����Kp�e���
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rexle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
Tkua07gB3/nVO3aPg7C3vEbDZCxT3WAMli2uZisYT6ozmdAlDsixLjipgFN4If3z
|
32
32
|
Ej0QR3kvGcAvFQ==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2015-
|
34
|
+
date: 2015-05-02 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rexleparser
|
metadata.gz.sig
CHANGED
Binary file
|