Class: Accessibility::Enumerators::DepthFirst
- Inherits:
-
Object
- Object
- Accessibility::Enumerators::DepthFirst
- Includes:
- Enumerable
- Defined in:
- lib/accessibility/enumerators.rb
Overview
Enumerator for visitng each element in a UI hierarchy in depth first order.
Instance Method Summary collapse
- #each {|| ... } ⇒ Object
-
#each_with_level {|, | ... } ⇒ Object
Walk the UI element tree and yield both the element and the level that the element is at relative to the root.
-
#initialize(root) ⇒ DepthFirst
constructor
A new instance of DepthFirst.
Constructor Details
#initialize(root) ⇒ DepthFirst
Returns a new instance of DepthFirst.
55 56 57 |
# File 'lib/accessibility/enumerators.rb', line 55 def initialize root @root = root end |
Instance Method Details
#each {|| ... } ⇒ Object
61 62 63 64 65 66 67 68 69 |
# 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 {|, | ... } ⇒ Object
Walk the UI element tree and yield both the element and the level that the element is at relative to the root.
78 79 80 81 82 83 |
# 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 |