rexle-xpath 0.2.6 → 0.2.7

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: e614fc69dcc5691190e32d9aba058c368e72e27d
4
- data.tar.gz: e31b42bba0e3beb282e84fd4094e766bb672f831
3
+ metadata.gz: 18b76b3785397c285d8ecedb10d9717490fd9e45
4
+ data.tar.gz: d5044d586690bc448ba9a8c0878ed2d77bd7a03f
5
5
  SHA512:
6
- metadata.gz: d3b6f149bc21889d548ebd46cc0ce18756cdb732ce9ab7c914354c934a6297dc8bf2529bad27ed3d35dc6ca0c0e2dc9bc3d9c419f096eea2610bb57c9b877008
7
- data.tar.gz: ebad27124d720982f43e5b822b2a6890595d07f82c380e8a851b2a961f61e3aa9a5362a235007aea87e5489ce2cd790021d9ccf1bd6f0cf72c7e00c19109546b
6
+ metadata.gz: 366a3f5ebb06eb8ce44897d677755536bace9bbcd8f53ef9bb8f03167a8e1cc6e0a56a70a1462bcbe1e8285b2c9133d4e75aec8f4310869ff87061251c8bd9df
7
+ data.tar.gz: 6fd386b3acd708c283d93ee3a9f709803bc2a99bbbd2b18d7f02f739e81673658c6db0098ef43ef6f5e0cdfb4267a772058a267a32d83d47420ced7f68692caa
checksums.yaml.gz.sig CHANGED
@@ -1,2 +1 @@
1
- �iZ��Q�&��`P�������s+�}C[�-\���!!&������%W�����pW$"O�w�<�L�.X���Z&`�8���]o3$m
2
- ����L3_։����G�H�;�r�P]O�0hPM�z�8��f���0���v���+n%��a
1
+ xgv���QU#�jdheE�ڶ�۷l�>jV���:�]6,y�(�m��w`�h�8�!�Ko �0��k�29t]�z��"��^�0�dg��p/ф�^�6�b�/Y{�)M�s}�7d�WR�l��?6l��=�����0ѧ���t���굹���j��^g��`C��r�
data/lib/rexle-xpath.rb CHANGED
@@ -7,10 +7,12 @@ require 'rexle-xpath-parser'
7
7
 
8
8
  class RexleXPath
9
9
 
10
- def initialize(node=nil)
10
+ def initialize(node=nil, debug: false)
11
11
 
12
- @node = node
13
12
 
13
+ @node = node
14
+ @debug = debug
15
+
14
16
  end
15
17
 
16
18
  def parse(s)
@@ -21,15 +23,19 @@ class RexleXPath
21
23
  when /^(\w+)\(\)$/
22
24
  @node.method(($1).to_sym).call
23
25
  else
24
- query @node, RexleXPathParser.new(s).to_a
26
+ a = RexleXPathParser.new(s).to_a
27
+ puts 'a: ' + a.inspect
28
+ query @node, a
25
29
  end
26
30
  end
27
31
 
28
32
  def query(node=@node, xpath_instructions)
29
33
 
34
+ debug :query, node: node, xpath_instructions: xpath_instructions
35
+
30
36
  r = []
31
37
 
32
- row = xpath_instructions.shift
38
+ row = xpath_instructions.shift
33
39
  method_name, *args = row
34
40
 
35
41
  return query node, row if row.first.is_a? Array
@@ -47,7 +53,7 @@ class RexleXPath
47
53
  r = node.attributes[key]
48
54
 
49
55
  xi = xpath_instructions
50
-
56
+
51
57
  if xi[0] and xi[0][0].to_sym == :value then
52
58
 
53
59
  _, operator, value = xi.shift
@@ -67,21 +73,25 @@ class RexleXPath
67
73
 
68
74
  def predicate(node, args, xpath_instructions)
69
75
 
76
+ debug :predicate, node: node, args: args,
77
+ xpath_instructions: xpath_instructions
78
+
70
79
  r = query node, args
71
- r ? r.any? : r
80
+ r.is_a?(Array) ? r.any? : r
81
+
72
82
  end
73
83
 
74
84
  def select(node, args, xpath_instructions)
75
85
 
76
86
  a = node.elements.select {|x| x.name == args.first }
77
-
78
87
  predicate = xpath_instructions.flatten.first.to_s == 'predicate'
79
88
 
80
89
  if xpath_instructions.any? and a.any? then
81
90
 
82
91
  a.inject([]) do |r, child_node|
83
-
84
- r2 = query(child_node, xpath_instructions.clone)
92
+
93
+ xi = Marshal.load( Marshal.dump(xpath_instructions) )
94
+ r2 = query(child_node, xi)
85
95
 
86
96
  case r2.class.to_s.to_sym
87
97
  when :'Rexle::Element' then r << r2
@@ -107,14 +117,20 @@ class RexleXPath
107
117
 
108
118
  operator, operand = args
109
119
 
110
- case operator.to_sym
111
- when :== then node.text == operand
112
- when :> then node.value > operand
113
- when :< then node.value < operand
114
- end
120
+ node.value.method(operator.to_sym).call operand
115
121
 
116
122
  end
117
123
 
118
124
  alias text value
119
125
 
126
+ def debug(method, h={})
127
+
128
+ return unless @debug
129
+
130
+ puts
131
+ puts '# inside ' + method.to_s
132
+ h.each {|k,v| puts "... %s: %s" % [k,v.inspect] }
133
+ puts
134
+
135
+ end
120
136
  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.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file