xpath 3.0.0 → 3.1.0
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 +5 -5
 - data/lib/xpath/dsl.rb +9 -1
 - data/lib/xpath/version.rb +1 -1
 - data/spec/fixtures/simple.html +4 -0
 - data/spec/xpath_spec.rb +23 -0
 - metadata +3 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 2 
     | 
    
         
            +
            SHA256:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 12f29349abdcae71838e3a6c0f9f6d7eac41b378e2fbdc3bcd6996950b76da7e
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 819e1a3641e979a632bf9358609da87155920ca1fc07e89b089b4a30e3681d39
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 5c6ee15be0134334b4cb7016b252da4985a8f356cba571b84078af03745c612b13640b1cc77617a5f80d90ab643b2401cfe08b5d96fe02affd010d627ede88a4
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 223c56e87b09e1cf7d89e44d8fe4ac1639ce91280392bbbe25fc8b78d6cbf19a613f1d87a9d6f4ace14ad4973c80fdd7a20cbd292f188ffa571e3b72a2145197
         
     | 
    
        data/lib/xpath/dsl.rb
    CHANGED
    
    | 
         @@ -41,7 +41,11 @@ module XPath 
     | 
|
| 
       41 
41 
     | 
    
         
             
                end
         
     | 
| 
       42 
42 
     | 
    
         | 
| 
       43 
43 
     | 
    
         
             
                def where(expression)
         
     | 
| 
       44 
     | 
    
         
            -
                   
     | 
| 
      
 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
         
     | 
    
        data/lib/xpath/version.rb
    CHANGED
    
    
    
        data/spec/fixtures/simple.html
    CHANGED
    
    
    
        data/spec/xpath_spec.rb
    CHANGED
    
    | 
         @@ -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. 
     | 
| 
      
 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:  
     | 
| 
      
 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 
     | 
| 
      
 125 
     | 
    
         
            +
            rubygems_version: 2.7.6
         
     | 
| 
       126 
126 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       127 
127 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       128 
128 
     | 
    
         
             
            summary: Generate XPath expressions from Ruby
         
     |