Sha256: 058443f839486e3f871f2ec9c484b3b610cf547838c987c861b89b37862cc9c5

Contents?: true

Size: 651 Bytes

Versions: 3

Compression:

Stored size: 651 Bytes

Contents

# -*- coding: utf-8 -*-
module TreeRb

  class DomWalker
    def initialize(node)
      @node = node
    end

    def run(visitor)
      @visitor = visitor
      process_node(@node)
    end


    #
    # recurse on nodes
    #
    def process_node(node, level=1)
      entries = node.children
      @visitor.enter_node(node)
      entries.each do |entry|
        unless is_leaf?(entry)
          process_node(entry, level+1)
        else
          @visitor.visit_leaf(entry)
        end
      end
      @visitor.exit_node(node)
    end

    def is_leaf?(node)
      node.node_type == Nokogiri::XML::Node::TEXT_NODE
    end

  end # class
end # module

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tree.rb-0.3.13 lib/tree_rb/input_plugins/html_page/dom_walker.rb
tree.rb-0.3.12 lib/tree_rb/input_plugins/html_page/dom_walker.rb
tree.rb-0.3.11 lib/tree_rb/input_html_page/dom_walker.rb