class Rpr::Formatter::Dot

Formatter for Graphviz

Public Class Methods

new() click to toggle source
# File lib/rpr/formatter/dot.rb, line 60
def initialize
  @id = :a
end
print(object) click to toggle source

Public Instance Methods

print(object) click to toggle source

Private Instance Methods

gen_id() click to toggle source
# File lib/rpr/formatter/dot.rb, line 87
def gen_id
  @id = @id.succ
end
traverse_and_print(object, parent = 'ROOT') click to toggle source
# File lib/rpr/formatter/dot.rb, line 72
def traverse_and_print(object, parent = 'ROOT')
  label = object.node_value
  shape = object.traversable? ? 'oval' : 'box'
  id = gen_id()

  puts "#{parent} -> #{id}"
  puts "#{id}[ label=#{label.inspect} shape=#{shape} ]"

  if object.traversable?
    object.children.each do |child|
      traverse_and_print(child, id)
    end
  end
end