class Gammo::XPath::AST::LocationPath
@!visibility private
Attributes
absolute[RW]
steps[RW]
Public Class Methods
new()
click to toggle source
# File lib/gammo/xpath/ast/path.rb, line 35 def initialize @absolute = false @steps = [] end
Public Instance Methods
append_step(step)
click to toggle source
# File lib/gammo/xpath/ast/path.rb, line 57 def append_step(step) steps << step end
evaluate(context)
click to toggle source
# File lib/gammo/xpath/ast/path.rb, line 40 def evaluate(context) # If this location path needs to be absolute and given context # is not document, this gets owner document node at first. cloned = context.dup context_node = context.node context_node = context_node.owner_document if absolute && !context_node.document? node_set = NodeSet.new node_set << context_node evaluate_with_node_set(cloned, node_set) Value::NodeSet.new(node_set) end
evaluate_with_node_set(context, node_set)
click to toggle source
# File lib/gammo/xpath/ast/path.rb, line 61 def evaluate_with_node_set(context, node_set) steps.each do |step| duplicates = Set.new([]) new_nodes = NodeSet.new includes_duplicate_nodes = (!node_set.subtrees_are_disjoint? || (!step.instance_of?(Axis::Child) && !step.instance_of?(Axis::Self) && !step.instance_of?(Axis::Descendant) && !step.instance_of?(Axis::DescendantOrSelf) && !step.instance_of?(Axis::Attribute))) if node_set.subtrees_are_disjoint? && (step.instance_of?(Axis::Child) || step.instance_of?(Axis::Self)) new_nodes.disjoint = true end node_set.dup.each_with_index do |node, i| matches = NodeSet.new step.evaluate_context_node_with_node_set(context, node, matches) matches.each do |node| new_nodes << node if !includes_duplicate_nodes || duplicates.add?(node) end end node_set.replace(new_nodes) end end
insert_first_step(step)
click to toggle source
# File lib/gammo/xpath/ast/path.rb, line 53 def insert_first_step(step) steps.unshift(step) end