module ClosureTree::Digraphs::ClassMethods

Public Instance Methods

to_dot_digraph(tree_scope) click to toggle source

Renders the given scope as a DOT digraph, suitable for rendering by Graphviz

# File lib/closure_tree/digraphs.rb, line 16
def to_dot_digraph(tree_scope)
  id_to_instance = tree_scope.reduce({}) { |h, ea| h[ea.id] = ea; h }
  output = StringIO.new
  output << "digraph G {\n"
  tree_scope.each do |ea|
    if id_to_instance.key? ea._ct_parent_id
      output << "  \"#{ea._ct_parent_id}\" -> \"#{ea._ct_id}\"\n"
    end
    output << "  \"#{ea._ct_id}\" [label=\"#{ea.to_digraph_label}\"]\n"
  end
  output << "}\n"
  output.string
end