rexle 0.9.28 → 0.9.29
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.
- data/lib/rexle.rb +42 -31
- metadata +1 -1
    
        data/lib/rexle.rb
    CHANGED
    
    | @@ -200,7 +200,7 @@ class Rexle | |
| 200 200 |  | 
| 201 201 | 
             
                    #results = raw_results.inject(&:+)
         | 
| 202 202 | 
             
                    results = raw_results.last
         | 
| 203 | 
            -
                    procs[results.class.to_s.to_sym].call(results)
         | 
| 203 | 
            +
                    procs[results.class.to_s.to_sym].call(results) if results
         | 
| 204 204 |  | 
| 205 205 | 
             
                  else
         | 
| 206 206 | 
             
                    m, xpath_value = fn_match.captures
         | 
| @@ -213,9 +213,9 @@ class Rexle | |
| 213 213 |  | 
| 214 214 | 
             
                  #remove any pre'fixes
         | 
| 215 215 | 
             
                 #@rexle.prefixes.each {|x| xpath_value.sub!(x + ':','') }
         | 
| 216 | 
            -
                  flag_func = false
         | 
| 216 | 
            +
                  flag_func = false            
         | 
| 217 217 |  | 
| 218 | 
            -
                  xpath_value = raw_xpath_value | 
| 218 | 
            +
                  xpath_value = raw_xpath_value #.sub(/^\[/,'*[')
         | 
| 219 219 | 
             
                  #xpath_value.sub!(/\.\/(?=[\/])/,'')
         | 
| 220 220 |  | 
| 221 221 | 
             
                  if xpath_value[/^[\w\/]+\s*=.*/] then        
         | 
| @@ -231,7 +231,7 @@ class Rexle | |
| 231 231 | 
             
                  #xpath_value.sub!(/^attribute::/,'*/attribute::')
         | 
| 232 232 | 
             
                  raw_path, raw_condition = xpath_value.sub(/^\.?\/(?!\/)/,'')\
         | 
| 233 233 | 
             
                      .match(/([^\[]+)(\[[^\]]+\])?/).captures 
         | 
| 234 | 
            -
             | 
| 234 | 
            +
             | 
| 235 235 | 
             
                  remaining_path = ($').to_s
         | 
| 236 236 |  | 
| 237 237 | 
             
                  r = raw_path[/([^\/]+)(?=\/\/)/,1] 
         | 
| @@ -249,20 +249,24 @@ class Rexle | |
| 249 249 | 
             
                    a_path.shift
         | 
| 250 250 | 
             
                    return @value
         | 
| 251 251 | 
             
                  else
         | 
| 252 | 
            +
             | 
| 252 253 | 
             
                    attribute = xpath_value[/^(attribute::|@)(.*)/,2] 
         | 
| 254 | 
            +
             | 
| 253 255 | 
             
                    return [@attributes[attribute.to_sym]] if attribute and @attributes and @attributes.has_key?(attribute.to_sym)
         | 
| 254 256 | 
             
                    s = a_path.shift
         | 
| 255 257 | 
             
                  end      
         | 
| 256 258 |  | 
| 257 259 | 
             
                  # isolate the xpath to return just the path to the current element
         | 
| 260 | 
            +
             | 
| 258 261 | 
             
                  elmnt_path = s[/^([\w:\*]+\[[^\]]+\])|[\/]+{,2}[^\/]+/]
         | 
| 259 262 | 
             
                  element_part = elmnt_path[/(^@?[^\[]+)?/,1] if elmnt_path
         | 
| 260 | 
            -
             | 
| 263 | 
            +
                  
         | 
| 261 264 | 
             
                  if element_part then
         | 
| 262 265 | 
             
                    unless element_part[/^@/] then
         | 
| 263 266 | 
             
                      element_name = element_part[/^[\w:\*\.]+/]
         | 
| 264 267 | 
             
                    else
         | 
| 265 | 
            -
             | 
| 268 | 
            +
             | 
| 269 | 
            +
                      condition = xpath_value[/^\[/] ? xpath_value : element_part
         | 
| 266 270 | 
             
                      element_name = nil
         | 
| 267 271 | 
             
                    end
         | 
| 268 272 |  | 
| @@ -270,9 +274,14 @@ class Rexle | |
| 270 274 |  | 
| 271 275 | 
             
                  #element_name ||= '*'
         | 
| 272 276 | 
             
                  raw_condition = '' if condition
         | 
| 273 | 
            -
             | 
| 274 277 | 
             
                  attr_search = format_condition(condition) if condition and condition.length > 0      
         | 
| 275 278 |  | 
| 279 | 
            +
                  attr_search2 = xpath_value[/^\[(.*)\]$/,1]
         | 
| 280 | 
            +
                  if attr_search2 then        
         | 
| 281 | 
            +
                    r4 = attribute_search(attr_search, self, self.attributes)
         | 
| 282 | 
            +
                    return r4
         | 
| 283 | 
            +
                  end      
         | 
| 284 | 
            +
                  
         | 
| 276 285 | 
             
                  return_elements = []
         | 
| 277 286 |  | 
| 278 287 | 
             
                  if raw_path[0,2] == '//' then
         | 
| @@ -282,15 +291,13 @@ class Rexle | |
| 282 291 | 
             
                    return  [self]
         | 
| 283 292 | 
             
                  else
         | 
| 284 293 |  | 
| 285 | 
            -
             | 
| 286 | 
            -
                       | 
| 287 | 
            -
             | 
| 288 | 
            -
             | 
| 289 | 
            -
                          (element_name == '*' && x[0].is_a?(Array))
         | 
| 290 | 
            -
                      end
         | 
| 294 | 
            +
                    return_elements = @child_lookup.map.with_index.select do |x|    
         | 
| 295 | 
            +
                      (x[0][0] == element_name || element_name == '.') or \
         | 
| 296 | 
            +
                        (element_name == '*' && x[0].is_a?(Array))
         | 
| 297 | 
            +
                    end
         | 
| 291 298 |  | 
| 292 299 | 
             
                  end
         | 
| 293 | 
            -
             | 
| 300 | 
            +
             | 
| 294 301 |  | 
| 295 302 | 
             
                  if return_elements.length > 0 then
         | 
| 296 303 |  | 
| @@ -520,7 +527,8 @@ class Rexle | |
| 520 527 |  | 
| 521 528 | 
             
                def scan_match(node, xpath)
         | 
| 522 529 |  | 
| 523 | 
            -
                  r = node.xpath(xpath[2..-1])
         | 
| 530 | 
            +
                  #r = node.xpath(xpath[2..-1].sub(/^\w+\/?/,''))
         | 
| 531 | 
            +
                  r = node.xpath(xpath[2..-1]) || []
         | 
| 524 532 | 
             
                  r << node.children.map {|n| scan_match(n, xpath) if n.is_a? Rexle::Element}
         | 
| 525 533 | 
             
                  r
         | 
| 526 534 | 
             
                end
         | 
| @@ -534,21 +542,7 @@ class Rexle | |
| 534 542 | 
             
                  h = x[0][1]  # <-- fetch the attributes      
         | 
| 535 543 |  | 
| 536 544 | 
             
                  if attr_search then
         | 
| 537 | 
            -
                     | 
| 538 | 
            -
                      block_given? ? blk.call(e) : e if i == attr_search 
         | 
| 539 | 
            -
                    elsif attr_search[/i\s[<>\=]\s\d+/] and eval(attr_search) then
         | 
| 540 | 
            -
                      block_given? ? blk.call(e) : e
         | 
| 541 | 
            -
                    elsif h and attr_search[/^h\[/] and eval(attr_search)
         | 
| 542 | 
            -
                      block_given? ? blk.call(e) : e
         | 
| 543 | 
            -
                    elsif attr_search[/^\(name ==/] and e.child_lookup.select{|name, attributes, value| eval(attr_search) }.length > 0
         | 
| 544 | 
            -
                      block_given? ? blk.call(e) : e
         | 
| 545 | 
            -
                    elsif attr_search[/^\(name ==/] and eval(attr_search) 
         | 
| 546 | 
            -
                      block_given? ? blk.call(e) : e          
         | 
| 547 | 
            -
                    elsif attr_search[/^e\.value/] and eval(attr_search)           
         | 
| 548 | 
            -
                      block_given? ? blk.call(e) : e
         | 
| 549 | 
            -
                    elsif attr_search[/^e\.xpath/] and eval(attr_search)           
         | 
| 550 | 
            -
                      block_given? ? blk.call(e) : e
         | 
| 551 | 
            -
                    end
         | 
| 545 | 
            +
                    attribute_search(attr_search,e, h, i, &blk)
         | 
| 552 546 | 
             
                  else
         | 
| 553 547 |  | 
| 554 548 | 
             
                    block_given? ? blk.call(e) : e
         | 
| @@ -556,6 +550,23 @@ class Rexle | |
| 556 550 |  | 
| 557 551 | 
             
                end
         | 
| 558 552 |  | 
| 553 | 
            +
                def attribute_search(attr_search, e, h, i=nil, &blk)
         | 
| 554 | 
            +
                  if attr_search.is_a? Fixnum then
         | 
| 555 | 
            +
                    block_given? ? blk.call(e) : e if i == attr_search 
         | 
| 556 | 
            +
                  elsif attr_search[/i\s[<>\=]\s\d+/] and eval(attr_search) then
         | 
| 557 | 
            +
                    block_given? ? blk.call(e) : e
         | 
| 558 | 
            +
                  elsif h and attr_search[/^h\[/] and eval(attr_search)
         | 
| 559 | 
            +
                    block_given? ? blk.call(e) : e
         | 
| 560 | 
            +
                  elsif attr_search[/^\(name ==/] and e.child_lookup.select{|name, attributes, value| eval(attr_search) }.length > 0
         | 
| 561 | 
            +
                    block_given? ? blk.call(e) : e
         | 
| 562 | 
            +
                  elsif attr_search[/^\(name ==/] and eval(attr_search) 
         | 
| 563 | 
            +
                    block_given? ? blk.call(e) : e          
         | 
| 564 | 
            +
                  elsif attr_search[/^e\.value/] and eval(attr_search)           
         | 
| 565 | 
            +
                    block_given? ? blk.call(e) : e
         | 
| 566 | 
            +
                  elsif attr_search[/^e\.xpath/] and eval(attr_search)           
         | 
| 567 | 
            +
                    block_given? ? blk.call(e) : e
         | 
| 568 | 
            +
                  end      
         | 
| 569 | 
            +
                end
         | 
| 559 570 | 
             
              end # -- end of element --
         | 
| 560 571 |  | 
| 561 572 | 
             
              class Elements
         | 
| @@ -683,4 +694,4 @@ class Rexle | |
| 683 694 | 
             
                [node.name, node.text.to_s, attributes, *children]
         | 
| 684 695 | 
             
              end
         | 
| 685 696 |  | 
| 686 | 
            -
            end
         | 
| 697 | 
            +
            end
         |