Changeset 141

Show
Ignore:
Timestamp:
04/18/2007 14:36:15 (20 months ago)
Author:
why
Message:
  • lib/hpricot/traverse.rb: honor the third dot in a Range, thanks MORGAN
Location:
trunk/lib/hpricot
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/hpricot/elements.rb

    r137 r141  
    244244    # Given two elements, attempt to gather an Elements array of everything between 
    245245    # (and including) those two elements. 
    246     def self.expand(ele1, ele2) 
     246    def self.expand(ele1, ele2, excl=false) 
    247247      ary = [] 
     248      offset = excl ? -1 : 0 
    248249 
    249250      if ele1 and ele2 
    250251        # let's quickly take care of siblings 
    251252        if ele1.parent == ele2.parent 
    252           ary = ele1.parent.children[ele1.node_position..ele2.node_position] 
     253          ary = ele1.parent.children[ele1.node_position..(ele2.node_position+offset)] 
    253254        else 
    254255          # find common parent 
     
    267268 
    268269          if child 
    269             ary = common_parent.children[0..child.node_position] 
     270            ary = common_parent.children[0..(child.node_position+offset)] 
    270271          end 
    271272        end 
  • trunk/lib/hpricot/traverse.rb

    r138 r141  
    6060      pos.map! do |r| 
    6161        if r.is_a?(Range) and r.begin.is_a?(String) 
    62           r = ((parent.index(r.begin)-si)..(parent.index(r.end)-si)) 
     62          r = Range.new(parent.index(r.begin)-si, parent.index(r.end)-si, r.exclude_end?) 
    6363        end 
    6464        r 
     
    237237    def search(expr, &blk) 
    238238      if Range === expr 
    239         return Elements.expand(at(expr.begin), at(expr.end)) 
     239        return Elements.expand(at(expr.begin), at(expr.end), expr.exclude_end?) 
    240240      end 
    241241      last = nil