Added Node#previous_element and Node#next_element.

These methods can be used similar to #previous and #next expect that they only
return Element instances opposed to all Node instances.
This commit is contained in:
Yorick Peterse committed 2014-07-04 10:18:18 +02:00
1 parent 94965961ce
commit e334e50ca6
2 files changed
+84 -10

No files matched your search

+30
View File
@@ -80,6 +80,36 @@ module Oga
return index <= length ? node_set[index] : nil
end
##
# Returns the previous element node or nil if there is none.
#
# @return [Oga::XML::Element]
#
def previous_element
node = self
while node = node.previous
return node if node.is_a?(Element)
end
return
end
##
# Returns the next element node or nil if there is none.
#
# @return [Oga::XML::Element]
#
def next_element
node = self
while node = node.next
return node if node.is_a?(Element)
end
return
end
##
# Returns the root document/node of the current node. The node is
# retrieved by traversing upwards in the DOM tree from the current node.