class Gammo::XPath::AST::Axis

Class for representing Axes. www.w3.org/TR/1999/REC-xpath-19991116/#axes @!visibility private

Attributes

node_test[R]
predicates[R]

Public Class Methods

new(node_test:, predicates: []) click to toggle source
# File lib/gammo/xpath/ast/axis.rb, line 16
def initialize(node_test:, predicates: [])
  @node_test = node_test
  @predicates = Array(predicates)
end

Public Instance Methods

evaluate_context_node_with_node_set(context, context_node, node_set) click to toggle source
# File lib/gammo/xpath/ast/axis.rb, line 21
def evaluate_context_node_with_node_set(context, context_node, node_set)
  context.position = 0
  # Strain nodes from context node for each axis.
  strain(context, context_node, node_set)
  # After straining try to filter by given predicates.
  predicates.each do |predicate|
    new_nodes = Gammo::XPath::NodeSet.new
    node_set.each_with_index do |node, i|
      context.node = node
      context.size = node_set.size
      context.position = i + 1
      new_nodes << node if predicate.evaluate(context)
    end
    node_set.replace(new_nodes)
  end
end