Changeset 141
- Timestamp:
- 04/18/2007 14:36:15 (20 months ago)
- Location:
- trunk/lib/hpricot
- Files:
-
- 2 modified
-
elements.rb (modified) (2 diffs)
-
traverse.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/hpricot/elements.rb
r137 r141 244 244 # Given two elements, attempt to gather an Elements array of everything between 245 245 # (and including) those two elements. 246 def self.expand(ele1, ele2 )246 def self.expand(ele1, ele2, excl=false) 247 247 ary = [] 248 offset = excl ? -1 : 0 248 249 249 250 if ele1 and ele2 250 251 # let's quickly take care of siblings 251 252 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)] 253 254 else 254 255 # find common parent … … 267 268 268 269 if child 269 ary = common_parent.children[0.. child.node_position]270 ary = common_parent.children[0..(child.node_position+offset)] 270 271 end 271 272 end -
trunk/lib/hpricot/traverse.rb
r138 r141 60 60 pos.map! do |r| 61 61 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?) 63 63 end 64 64 r … … 237 237 def search(expr, &blk) 238 238 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?) 240 240 end 241 241 last = nil
