class Accessibility::Enumerators::BreadthFirst
Enumerator for visiting each element in a UI hierarchy in breadth first order.
Public Class Methods
new(root)
click to toggle source
@param root [#children]
# File lib/accessibility/enumerators.rb, line 12 def initialize root @root = root end
Public Instance Methods
each() { |x end| ... }
click to toggle source
Semi-lazily iterate through the tree.
@yield An element in the UI hierarchy @yieldparam [AX::Element,AXUIElementRef]
# File lib/accessibility/enumerators.rb, line 21 def each queue = [@root] until queue.empty? kids = queue.shift.children kids.each do |x| yield x end queue.concat kids end end ## # @note Explicitly defined so that escaping at the first found # element actually works. Since only a single `break` is # called when an item is found it does not fully escape the # built in implementation. Technically, we need to do this # with other 'escape-early' iteraters, but they aren't # being used...yet. # # Override `Enumerable#find` for performance reasons. # # @yield An element in the UI hierarchy # @yieldparam [AX::Element,AXUIElementRef] def find each { |x| return x if yield x } end end
find() { |x| ... }
click to toggle source
@note Explicitly defined so that escaping at the first found
element actually works. Since only a single `break` is called when an item is found it does not fully escape the built in implementation. Technically, we need to do this with other 'escape-early' iteraters, but they aren't being used...yet.
Override ‘Enumerable#find` for performance reasons.
@yield An element in the UI hierarchy @yieldparam [AX::Element,AXUIElementRef]
# File lib/accessibility/enumerators.rb, line 42 def find each { |x| return x if yield x } end