rexle-xpath 0.2.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e3af7b969033bc79cda32bf7ab3a65d9b54cc9e
4
- data.tar.gz: 32b1214acd14d40e15c91ad212c13f6a9d279f9c
3
+ metadata.gz: c52bf8349947a0e61c02afe25159018258601053
4
+ data.tar.gz: 0559638004066be9017d6b69f3d7bcaf89345a01
5
5
  SHA512:
6
- metadata.gz: c0fa3140fc5bf40451319decd8aa432ddb235f6c7f8e0f6de79da0fce45d0cfa04557458e7b12733c0b7a79f0c2fac4175b8dc2927b5b142acd631e2e686dd13
7
- data.tar.gz: 253b0aa1f5a1aeeba768ff5d5dd3d0f0a80f0e5d6c58843bc2dfa0fd86431903f285c06af1ad209e70a0be1a7b7ee8f204dbbc92194560cac822a04c9f832ce4
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 = XPathObject.new(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
- a = if method_name == :select then
38
+ result = if method_name.to_sym == :select then
39
+
40
+ method(:select).call node, args, xpath_instructions
36
41
 
37
- r = node.select args.first
42
+ elsif method_name.to_sym == :text or method_name.to_sym == :value then
38
43
 
39
- if xpath_instructions.any? and r.any? then
40
- r.map {|child_node| query(child_node, xpath_instructions) }
41
- else
42
- r
43
- end
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
- a.flatten
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
- class XPathObject
71
+ a = node.select args.first
56
72
 
57
- def initialize(element)
58
- @element = element
59
- end
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
- def name()
62
- @element.name()
63
- end
102
+ operator, operand = args
64
103
 
65
- def not()
66
- @element
67
- end
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.1
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-05 00:00:00.000000000 Z
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