class BetterHtml::AST::Iterator
Public Class Methods
descendants(root_node, type)
click to toggle source
# File lib/better_html/ast/iterator.rb, line 24 def self.descendants(root_node, type) Enumerator.new do |yielder| t = new(type) { |node| yielder << node } t.traverse(root_node) end end
new(types, &block)
click to toggle source
# File lib/better_html/ast/iterator.rb, line 7 def initialize(types, &block) @types = types.nil? ? nil : Array.wrap(types) @block = block end
Public Instance Methods
traverse(node)
click to toggle source
# File lib/better_html/ast/iterator.rb, line 12 def traverse(node) return unless node.is_a?(::AST::Node) @block.call(node) if @types.nil? || @types.include?(node.type) traverse_all(node) end
traverse_all(nodes)
click to toggle source
# File lib/better_html/ast/iterator.rb, line 18 def traverse_all(nodes) nodes.to_a.each do |node| traverse(node) if node.is_a?(::AST::Node) end end