xpath 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ae41f677ac864edf9c7689365012dc5f73731f61
4
- data.tar.gz: 63f10b70109aa842ac464b8491071a286b583f4c
2
+ SHA256:
3
+ metadata.gz: 12f29349abdcae71838e3a6c0f9f6d7eac41b378e2fbdc3bcd6996950b76da7e
4
+ data.tar.gz: 819e1a3641e979a632bf9358609da87155920ca1fc07e89b089b4a30e3681d39
5
5
  SHA512:
6
- metadata.gz: 7683342805b10e97fcb6593148c0beedb6ad43b7087915697b4a87b4127d88d1669e9e3d6a630a019a500c2203eff4a8b6c702e8bedb313ee41ca1ad726be446
7
- data.tar.gz: 4d9146f6cd818e364b94b95f219d40a70571c33a01faa58af9feccb7d3f40d7f0e1b0d9093ef1aec4aae2429859001fa15e341a032a4248575804886e0fd8344
6
+ metadata.gz: 5c6ee15be0134334b4cb7016b252da4985a8f356cba571b84078af03745c612b13640b1cc77617a5f80d90ab643b2401cfe08b5d96fe02affd010d627ede88a4
7
+ data.tar.gz: 223c56e87b09e1cf7d89e44d8fe4ac1639ce91280392bbbe25fc8b78d6cbf19a613f1d87a9d6f4ace14ad4973c80fdd7a20cbd292f188ffa571e3b72a2145197
@@ -41,7 +41,11 @@ module XPath
41
41
  end
42
42
 
43
43
  def where(expression)
44
- Expression.new(:where, current, expression)
44
+ if expression
45
+ Expression.new(:where, current, expression)
46
+ else
47
+ current
48
+ end
45
49
  end
46
50
  alias_method :[], :where
47
51
 
@@ -134,6 +138,10 @@ module XPath
134
138
 
135
139
  alias_method :self_axis, :self
136
140
 
141
+ def ends_with(suffix)
142
+ function(:substring, current, function(:'string-length', current).minus(function(:'string-length', suffix)).plus(1)) == suffix
143
+ end
144
+
137
145
  def contains_word(word)
138
146
  function(:concat, " ", current.normalize_space, " ").contains(" #{word} ")
139
147
  end
@@ -1,3 +1,3 @@
1
1
  module XPath
2
- VERSION = '3.0.0'
2
+ VERSION = '3.1.0'
3
3
  end
@@ -45,5 +45,9 @@
45
45
  <span id="substring">Hello there</span>
46
46
 
47
47
  <span id="string-length">Hello there</span>
48
+
49
+ <div id="oof" title="viDoof" data="id">
50
+ <p id="viDoof">Blah</p>
51
+ </div>
48
52
  </body>
49
53
  </html>
@@ -192,6 +192,25 @@ describe XPath do
192
192
  end
193
193
  end
194
194
 
195
+ describe '#ends_with' do
196
+ it "should find nodes that end with the given string" do
197
+ @results = xpath do |x|
198
+ x.descendant(:*).where(x.attr(:id).ends_with('oof'))
199
+ end
200
+ @results.size.should eq 2
201
+ @results[0][:id].should eq "oof"
202
+ @results[1][:id].should eq "viDoof"
203
+ end
204
+
205
+ it "should find nodes that contain the given expression" do
206
+ @results = xpath do |x|
207
+ expression = x.anywhere(:div).where(x.attr(:title) == 'viDoof').attr(:id)
208
+ x.descendant(:div).where(x.attr(:title).ends_with(expression))
209
+ end
210
+ @results[0][:id].should eq "oof"
211
+ end
212
+ end
213
+
195
214
  describe '#text' do
196
215
  it "should select a node's text" do
197
216
  @results = xpath { |x| x.descendant(:p).where(x.text == 'Bax') }
@@ -247,6 +266,10 @@ describe XPath do
247
266
  it "should be aliased as []" do
248
267
  xpath { |x| x.descendant(:div)[:"@id = 'foo'"] }.first[:title].should eq "fooDiv"
249
268
  end
269
+
270
+ it "should be a no-op when nil condition is passed" do
271
+ XPath.descendant(:div).where(nil).to_s.should eq ".//div"
272
+ end
250
273
  end
251
274
 
252
275
  describe '#inverse' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xpath
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Nicklas
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - gem-public_cert.pem
12
- date: 2017-12-30 00:00:00.000000000 Z
12
+ date: 2018-05-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
122
  version: '0'
123
123
  requirements: []
124
124
  rubyforge_project:
125
- rubygems_version: 2.6.13
125
+ rubygems_version: 2.7.6
126
126
  signing_key:
127
127
  specification_version: 4
128
128
  summary: Generate XPath expressions from Ruby