Class: Fabulator::Expr::AxisDescendentOrSelf

Inherits:
Object
  • Object
show all
Defined in:
lib/fabulator/expr/axis_descendent_or_self.rb

Instance Method Summary collapse

Constructor Details

#initialize(step = nil) ⇒ AxisDescendentOrSelf

Returns a new instance of AxisDescendentOrSelf.



4
5
6
# File 'lib/fabulator/expr/axis_descendent_or_self.rb', line 4

def initialize(step = nil)
  @step = step
end

Instance Method Details

#run(context, autovivify = false) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fabulator/expr/axis_descendent_or_self.rb', line 8

def run(context, autovivify = false)
  if context.is_a?(Array)
    stack = context.root
  else
    stack = [ context.root ]
  end
  possible = [ ]
  while !stack.empty?
    c = stack.shift

    stack = stack + c.children

    possible = possible + context.with_root(c).run(@step, autovivify)
  end
  return possible.uniq
end