rexle-xpath 0.2.12 → 0.2.13

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: 479dc6d4c1f6c7c3270c9966af77acad9efc3654
4
- data.tar.gz: b739041bf097a2faf1deb484744ba3a62d6a5615
3
+ metadata.gz: 1d4007487547f7b0f7fb68a76cfb7fd1a8874517
4
+ data.tar.gz: 14422d54c789930a6175158910adf52ce4c4a70b
5
5
  SHA512:
6
- metadata.gz: c4262efd3070eceb1d64dd5ca592f288392862f56ae5c8938418f30b8aedfb064137ec9db8fd2f25df807bc4954c6d1fc63468ced5bdf06f9a7d0fcbb2740544
7
- data.tar.gz: f5e6f9a12c7399f4e2e3940ae91e7206b5d4e7172aa5de7f8104f02d56279ee3abdbf050430e79269ad779133276759bbdf883b1d5a2dcb6c5876765c8682b58
6
+ metadata.gz: 38453d905aa27badd643941901d433068da7980be5a1f4b9d6650ab1ff822492bd5f620336d6691728a25ec3115ee5632baa7e6e39ddd25713e3ee46c107da62
7
+ data.tar.gz: e302f65667fc1df02ba00c3bd188dba19c81f767752e7057a2152bff2911e930862da20e32cdabcca19044d7174260975ce03546d5740b7245e55cad3d3b1ec6
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -29,13 +29,19 @@ class RexleXPath
29
29
  end
30
30
 
31
31
  def parse(s)
32
-
33
- case s
34
32
 
35
- # it's an xpath function
36
- when /^(\w+)\(\)$/
37
- @node.method(($1).to_sym).call
33
+ # it's an xpath function only
34
+ if /^(?<name>\w+)\(\)$/ =~ s
35
+
36
+ @node.method((name).to_sym).call
37
+
38
+ # it's an element only
39
+ elsif /^(?<name>\w+)$/ =~ s
40
+
41
+ select(@node, [name])
42
+
38
43
  else
44
+
39
45
  a = RexleXPathParser.new(s).to_a
40
46
  #puts 'a: ' + a.inspect
41
47
  query @node, a
@@ -122,19 +128,17 @@ class RexleXPath
122
128
  a = []
123
129
  a << query(node, xi.deep_clone)
124
130
 
125
- node.each_recursive do |e|
126
- a << query(e, xi.deep_clone)
127
- end
131
+ node.each_recursive {|e| a << query(e, xi.deep_clone) }
128
132
 
129
133
  a
130
134
  end
131
135
 
132
- def select(node, args, xpath_instructions)
136
+ def select(node, args, xpath_instructions=[])
133
137
 
134
138
  debug :select, node: node, args: args,
135
139
  xpath_instructions: xpath_instructions
136
140
 
137
- a = node.elements.select {|x| x.name == args.first }
141
+ nodes_found = node.elements.select {|x| x.name == args.first }
138
142
  flat_xpi = xpath_instructions.flatten
139
143
 
140
144
  predicate = flat_xpi.first.to_s == 'predicate'
@@ -142,13 +146,13 @@ class RexleXPath
142
146
  if predicate and flat_xpi[1] == :index then
143
147
 
144
148
  i = flat_xpi[2].to_i - 1
145
- return a[i]
149
+ return nodes_found[i]
146
150
 
147
151
  end
148
152
 
149
- if xpath_instructions.any? and a.any? then
153
+ if xpath_instructions.any? and nodes_found.any? then
150
154
 
151
- a.inject([]) do |r, child_node|
155
+ nodes_found.inject([]) do |r, child_node|
152
156
 
153
157
  # deep clone the xpath instructions
154
158
  xi = xpath_instructions.deep_clone
@@ -172,11 +176,15 @@ class RexleXPath
172
176
  end # /inject
173
177
 
174
178
  else
175
- a
179
+ nodes_found
176
180
  end # /if
177
181
 
178
182
  end
179
183
 
184
+ def text(node, args, xpath_instructions)
185
+ node.text
186
+ end
187
+
180
188
  def value(node, args, xpath_instructions)
181
189
 
182
190
  operator, operand = args
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.12
4
+ version: 0.2.13
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-24 00:00:00.000000000 Z
34
+ date: 2016-05-25 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