Changeset 122
- Timestamp:
- 03/22/2007 22:34:49 (21 months ago)
- Files:
-
- 1 modified
-
trunk/lib/hpricot/traverse.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/hpricot/traverse.rb
r116 r122 60 60 # Returns the node neighboring this node to the south: just below it. 61 61 # This method includes text nodes and comments and such. 62 def next _node62 def next 63 63 sib = parent.children 64 64 sib[sib.index(self) + 1] if parent 65 65 end 66 alias_method :next_node, :next 66 67 67 68 # Returns to node neighboring this node to the north: just above it. 68 69 # This method includes text nodes and comments and such. 69 def previous _node70 def previous 70 71 sib = parent.children 71 72 x = sib.index(self) - 1 72 73 sib[x] if sib and x >= 0 73 74 end 75 alias_method :previous_node, :previous 76 77 # Find all preceding nodes. 78 def preceding 79 sibs = parent.children 80 si = sibs.index(self) 81 return Elements[*sibs[0...si]] 82 end 83 84 # Find all nodes which follow the current one. 85 def following 86 sibs = parent.children 87 si = sibs.index(self) + 1 88 return Elements[*sibs[si...sibs.length]] 89 end 74 90 75 91 # Adds elements immediately after this element, contained in the +html+ string. … … 365 381 end 366 382 383 # Find all preceding sibling elements. Like the other "sibling" methods, this weeds 384 # out text and comment nodes. 385 def preceding_siblings() 386 sibs = parent.containers 387 si = sibs.index(self) 388 return Elements[*sibs[0...si]] 389 end 390 391 # Find sibling elements which follow the current one. Like the other "sibling" methods, this weeds 392 # out text and comment nodes. 393 def following_siblings() 394 sibs = parent.containers 395 si = sibs.index(self) + 1 396 return Elements[*sibs[si...sibs.length]] 397 end 398 367 399 # Puts together an array of neighboring sibling elements based on their proximity 368 400 # to this element.
