class Accessibility::Enumerators::BreadthFirst::DepthFirst
Enumerator for visitng each element in a UI hierarchy in depth first order.
Public Class Methods
new(root)
click to toggle source
@param root [#children]
# File lib/accessibility/enumerators.rb, line 55 def initialize root @root = root end
Public Instance Methods
each() { |current| ... }
click to toggle source
@yield An element in the UI hierarchy @yieldparam [AX::Element,AXUIElementRef]
# File lib/accessibility/enumerators.rb, line 61 def each stack = @root.children until stack.empty? current = stack.shift yield current # needed to reverse, child ordering matters in practice stack.unshift *current.children end end
each_with_level(&block)
click to toggle source
Walk the UI element tree and yield both the element and the level that the element is at relative to the root.
@yield An element in the UI hierarchy @yieldparam [AX::Element,AXUIElementRef] @yieldparam [Number]
# File lib/accessibility/enumerators.rb, line 78 def each_with_level &block # @todo A bit of a hack that I would like to fix one day... @root.children.each do |element| recursive_each_with_level element, 1, block end end
Private Instance Methods
recursive_each_with_level(element, depth, block)
click to toggle source
Recursive implementation of a depth first iterator.
@param element [AX::Element] @param depth [Number] @param block [#call]
# File lib/accessibility/enumerators.rb, line 94 def recursive_each_with_level element, depth, block block.call element, depth element.children.each do |x| recursive_each_with_level x, depth + 1, block end end