From 1916799fef677af14c65ff78da5a0a5e68fe717b Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 25 Jul 2014 21:24:29 +0200 Subject: [PATCH] Basic boilerplate for descendant-or-self. --- lib/oga/xpath/evaluator.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb index 3cb68c9..6eb36a4 100644 --- a/lib/oga/xpath/evaluator.rb +++ b/lib/oga/xpath/evaluator.rb @@ -218,7 +218,7 @@ module Oga end ## - # Evaluator the `descendant` axis. This method processes child nodes until + # Evaluates the `descendant` axis. This method processes child nodes until # the very end of the tree, no "short-circuiting" mechanism is used. # # @param [Oga::XPath::Node] node @@ -226,6 +226,24 @@ module Oga # @return [Oga::XML::NodeSet] # def on_axis_descendant(node, context) + nodes = XML::NodeSet.new + children = child_nodes(context) + + unless children.empty? + nodes += on_axis_descendant(node, children) + end + + return nodes + end + + ## + # Evaluates the `descendant-or-self` axis. + # + # @param [Oga::XPath::Node] node + # @param [Oga::XML::NodeSet] context + # @return [Oga::XML::NodeSet] + # + def on_axis_descendant_or_self(node, context) nodes = on_test(node, context) children = child_nodes(context)