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
# File lib/rpr/formatter/dot.rb, line 56 def self.print(object) self.new.print(object) end
Public Instance Methods
print(object)
click to toggle source
# File lib/rpr/formatter/dot.rb, line 64 def print(object) puts 'digraph{graph [dpi=288;];' traverse_and_print(object) puts "}" end
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