rexle-xpath 0.2.2 → 0.2.3

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: c52bf8349947a0e61c02afe25159018258601053
4
- data.tar.gz: 0559638004066be9017d6b69f3d7bcaf89345a01
3
+ metadata.gz: 7715f6fa6fed4841965fe1e1b72a32222f47a242
4
+ data.tar.gz: 6c17c63d65f2c6b0ece0410ecbb63b2c021d1dfc
5
5
  SHA512:
6
- metadata.gz: c2e1dd34f9b3d221083ad78c9a59e19c782a9c004afd677b979b17173988680cd31e72a0a21c7903930d1f304bdfb75cdcb41e7051f363b003794915ebefef6d
7
- data.tar.gz: 06f0e9db668e535a4d99f6dc4e599ddbbb34d5f502decf469c88d332e487cd4e65f143d0f2fd564261b27a7a7df9e2c87efeb814fa8e919fd54bd695eeb647a4
6
+ metadata.gz: 886a1cc9f4d53176fb1103f7dc57a849563330cb8d6fb7850c21b32573973fd58f9a406efb4e7abcdc3aeb7c5c93eafa289e7d5fac8f21cd27f31a19ef20cda5
7
+ data.tar.gz: 7f70490345d52947f38424eda78b7321b01c91c4ce8e0afd9cc5c31509b01a5ca7224150f897ff4b59af23c76f9b63a150dd7b0348d4ea1ed2fb5dadb88c52cf
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
@@ -1,3 +1,2 @@
1
- K�C{
2
- �ˈ"�L��q��EL��� �C����^U�>g2 ���O���R.�%spi Wa�+�E��K�ڟ�0#rY��Dʀ��.�X��d�i���/N@�}9mb�9|@�c��Gn{ Ғ�wIr�Ն��� nD����kx#�֐g]�L
3
- ��S�`H�pP@EР����Vx?�Jgڋ���ͪ|J�9,���>���~��q�E ����y4�w�FK�IA��x!�S��p�y� 
1
+ j�؜�J�+8��� ��]/���z�A��.Q����$���}23��2��K�jAQnoc0�mDh"5�ٕ��ޚ�o�P`��A��T���} �o��2a������Tc)��̵���ʰ��2���@S�M}~AM��kbg�[�K]�V�6ϡ
2
+ ⒖qL;�T��� ��S���_a6G�]C�=~����=�yʀ��/~���i8~DKL�sފOa��wj���KhQ����HG,�\z��5���
data/lib/rexle-xpath.rb CHANGED
@@ -29,86 +29,74 @@ class RexleXPath
29
29
 
30
30
  r = []
31
31
 
32
- row = xpath_instructions.shift
33
-
32
+ row = xpath_instructions.shift
34
33
  method_name, *args = row
35
34
 
36
- return query node, row if row.first.is_a? Array
37
-
38
- result = if method_name.to_sym == :select then
39
-
40
- method(:select).call node, args, xpath_instructions
41
-
42
- elsif method_name.to_sym == :text or method_name.to_sym == :value then
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
49
-
50
- elsif row.is_a? Array then
51
- query node, row
52
- else
53
- []
54
- end
35
+ return query node, row if row.first.is_a? Array
55
36
 
37
+ result = method(method_name.to_sym).call node, args, xpath_instructions
56
38
  result.is_a?(Array) ? result.flatten : result
57
39
 
58
40
  end
59
41
 
60
42
  private
61
43
 
44
+ def not(node, args, xpath_instructions)
45
+
46
+ r = query node, xpath_instructions
47
+ !(r ? r.any? : r)
48
+ end
49
+
62
50
  def predicate(node, args, xpath_instructions)
63
51
 
64
- a = args
65
- r = query node, a
66
- r ? r.any? : r
52
+ r = query node, args
53
+ r ? r.any? : r
67
54
  end
68
55
 
69
56
  def select(node, args, xpath_instructions)
70
57
 
71
58
  a = node.select args.first
72
59
 
60
+ predicate = xpath_instructions.flatten.first.to_s == 'predicate'
61
+
73
62
  if xpath_instructions.any? and a.any? then
74
63
 
75
64
  a.inject([]) do |r, child_node|
76
65
 
77
66
  r2 = query(child_node, xpath_instructions.clone)
78
67
 
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
68
+ case r2.class.to_s.to_sym
69
+ when :'Rexle::Element' then r << r2
70
+ when :TrueClass
71
+ predicate ? r << child_node : r << true
72
+ when :FalseClass
73
+ !predicate ? r << false : r
85
74
  else
86
-
87
- if r2.any? then
88
- r << r2
89
- else
90
- r
91
- end
92
- end
75
+
76
+ r2.any? ? r << r2 : r
77
+
78
+ end # /case
93
79
 
94
- end
80
+ end # /inject
81
+
95
82
  else
96
83
  a
97
- end
84
+ end # /if
85
+
98
86
  end
99
87
 
100
88
  def value(node, args, xpath_instructions)
101
89
 
102
90
  operator, operand = args
103
91
 
104
- r = case operator.to_sym
92
+ case operator.to_sym
105
93
  when :== then node.text == operand
106
94
  when :> then node.value > operand
107
95
  when :< then node.value < operand
108
96
  end
109
-
110
- r
111
97
 
112
98
  end
113
99
 
100
+ alias text value
101
+
114
102
  end
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.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file