class NodeRenderer

Public Class Methods

new(tree) click to toggle source
# File lib/domparser/node_renderer.rb, line 2
def initialize tree
  @tree = tree
  @type_hash = nil
  @general_hash = nil
end

Public Instance Methods

detail_print_all(data) click to toggle source
# File lib/domparser/node_renderer.rb, line 66
def detail_print_all data
  unless data.type.nil?
    type_hash = {}
    type_hash[data.type] = data.attributes
    @type_hash[type_hash] += 1
  end
  return if data.children.empty?
  data.children.each do |child|
    detail_print_all child
  end
end
detail_print_hash(hash) click to toggle source
# File lib/domparser/node_renderer.rb, line 49
def detail_print_hash hash
  hash.each do |key, type_count|
    key.each do |type, attributes|
      if attributes.empty?
        puts "#{type_count} #{type}"
        puts "-" * 100
      else
        puts "#{type_count} #{type} with following attributes:"
        attributes.each do |attr_name, attr_value|
          puts "    #{attr_name} : #{attr_value}"
        end
        puts "-" * 100
      end
    end
  end
end
general_print_all(data) click to toggle source
# File lib/domparser/node_renderer.rb, line 34
def general_print_all data
  @general_hash[data.type] += 1 unless data.type.nil?
  return if data.children.empty?
  data.children.each do |child|
    general_print_all child
  end
end
print_all() click to toggle source
print_general_hash(hash) click to toggle source
print_node(node) click to toggle source
render(node = nil) click to toggle source
# File lib/domparser/node_renderer.rb, line 8
def render node = nil
  if node.nil?
    print_all
  else
    print_node node
  end
end