rexle-xpath 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/rexle-xpath.rb +65 -30
- data.tar.gz.sig +0 -0
- 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: c52bf8349947a0e61c02afe25159018258601053
|
4
|
+
data.tar.gz: 0559638004066be9017d6b69f3d7bcaf89345a01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2e1dd34f9b3d221083ad78c9a59e19c782a9c004afd677b979b17173988680cd31e72a0a21c7903930d1f304bdfb75cdcb41e7051f363b003794915ebefef6d
|
7
|
+
data.tar.gz: 06f0e9db668e535a4d99f6dc4e599ddbbb34d5f502decf469c88d332e487cd4e65f143d0f2fd564261b27a7a7df9e2c87efeb814fa8e919fd54bd695eeb647a4
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/rexle-xpath.rb
CHANGED
@@ -9,7 +9,7 @@ class RexleXPath
|
|
9
9
|
|
10
10
|
def initialize(node=nil)
|
11
11
|
|
12
|
-
@node =
|
12
|
+
@node = node
|
13
13
|
|
14
14
|
end
|
15
15
|
|
@@ -25,22 +25,27 @@ class RexleXPath
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def query(node, xpath_instructions)
|
29
|
-
|
28
|
+
def query(node=@node, xpath_instructions)
|
29
|
+
|
30
30
|
r = []
|
31
|
-
row = xpath_instructions.shift
|
32
31
|
|
32
|
+
row = xpath_instructions.shift
|
33
|
+
|
33
34
|
method_name, *args = row
|
35
|
+
|
36
|
+
return query node, row if row.first.is_a? Array
|
34
37
|
|
35
|
-
|
38
|
+
result = if method_name.to_sym == :select then
|
39
|
+
|
40
|
+
method(:select).call node, args, xpath_instructions
|
36
41
|
|
37
|
-
|
42
|
+
elsif method_name.to_sym == :text or method_name.to_sym == :value then
|
38
43
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
+
method(:value).call node, args, xpath_instructions
|
45
|
+
|
46
|
+
elsif method_name.to_sym == :predicate then
|
47
|
+
|
48
|
+
method(:predicate).call node, args, xpath_instructions
|
44
49
|
|
45
50
|
elsif row.is_a? Array then
|
46
51
|
query node, row
|
@@ -48,32 +53,62 @@ class RexleXPath
|
|
48
53
|
[]
|
49
54
|
end
|
50
55
|
|
51
|
-
|
56
|
+
result.is_a?(Array) ? result.flatten : result
|
52
57
|
|
53
58
|
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def predicate(node, args, xpath_instructions)
|
63
|
+
|
64
|
+
a = args
|
65
|
+
r = query node, a
|
66
|
+
r ? r.any? : r
|
67
|
+
end
|
68
|
+
|
69
|
+
def select(node, args, xpath_instructions)
|
54
70
|
|
55
|
-
|
71
|
+
a = node.select args.first
|
56
72
|
|
57
|
-
|
58
|
-
|
59
|
-
|
73
|
+
if xpath_instructions.any? and a.any? then
|
74
|
+
|
75
|
+
a.inject([]) do |r, child_node|
|
76
|
+
|
77
|
+
r2 = query(child_node, xpath_instructions.clone)
|
78
|
+
|
79
|
+
if r2.is_a? Rexle::Element then
|
80
|
+
r << r2
|
81
|
+
elsif r2 == true
|
82
|
+
r << child_node
|
83
|
+
elsif r2 == false
|
84
|
+
r
|
85
|
+
else
|
86
|
+
|
87
|
+
if r2.any? then
|
88
|
+
r << r2
|
89
|
+
else
|
90
|
+
r
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
else
|
96
|
+
a
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def value(node, args, xpath_instructions)
|
60
101
|
|
61
|
-
|
62
|
-
@element.name()
|
63
|
-
end
|
102
|
+
operator, operand = args
|
64
103
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
def select(name)
|
70
|
-
@element.select(name)
|
71
|
-
end
|
72
|
-
|
73
|
-
def text()
|
74
|
-
@element.text()
|
104
|
+
r = case operator.to_sym
|
105
|
+
when :== then node.text == operand
|
106
|
+
when :> then node.value > operand
|
107
|
+
when :< then node.value < operand
|
75
108
|
end
|
76
109
|
|
110
|
+
r
|
111
|
+
|
77
112
|
end
|
78
|
-
|
113
|
+
|
79
114
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rexle-xpath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
05Hvy/ad61XnzWtun98claEIk/rC/TxPrbRaOd7vN99WxTy1xn8ElfLSx7CDDrTc
|
32
32
|
qN5t1BlRcAgKNw==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2016-05-
|
34
|
+
date: 2016-05-07 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rexle-xpath-parser
|
metadata.gz.sig
CHANGED
Binary file
|