Class: TreeRb::DomWalker
- Inherits:
-
Object
- Object
- TreeRb::DomWalker
- Defined in:
- lib/tree_rb/input_plugins/html_page/dom_walker.rb
Instance Method Summary collapse
-
#initialize(node) ⇒ DomWalker
constructor
A new instance of DomWalker.
- #is_leaf?(node) ⇒ Boolean
-
#process_node(node, level = 1) ⇒ Object
recurse on nodes.
- #run(visitor) ⇒ Object
Constructor Details
#initialize(node) ⇒ DomWalker
Returns a new instance of DomWalker.
5 6 7 |
# File 'lib/tree_rb/input_plugins/html_page/dom_walker.rb', line 5 def initialize(node) @node = node end |
Instance Method Details
#is_leaf?(node) ⇒ Boolean
31 32 33 |
# File 'lib/tree_rb/input_plugins/html_page/dom_walker.rb', line 31 def is_leaf?(node) node.node_type == Nokogiri::XML::Node::TEXT_NODE end |
#process_node(node, level = 1) ⇒ Object
recurse on nodes
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/tree_rb/input_plugins/html_page/dom_walker.rb', line 18 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 |
#run(visitor) ⇒ Object
9 10 11 12 |
# File 'lib/tree_rb/input_plugins/html_page/dom_walker.rb', line 9 def run(visitor) @visitor = visitor process_node(@node) end |