class Rattler::Util::GraphViz::DigraphBuilder
DigraphBuilder
is used to build GraphViz
objects representing trees of nodes.
Public Class Methods
digraph(root, name='G')
click to toggle source
@param (see initialize) @return a new GraphViz
digraph object representing root
# File lib/rattler/util/graphviz/digraph_builder.rb, line 18 def self.digraph(root, name='G') self.new(root, name).digraph end
new(root, name='G')
click to toggle source
Create a new digraph builder for root
.
@param root the root node @param [String] name the name of the graph
# File lib/rattler/util/graphviz/digraph_builder.rb, line 26 def initialize(root, name='G') @root = root @g = ::GraphViz.digraph(name) @nodes = {} @node_serial = 0 end
Public Instance Methods
digraph()
click to toggle source
@return a new GraphViz
digraph object representing the root object
# File lib/rattler/util/graphviz/digraph_builder.rb, line 34 def digraph @digraph ||= begin node(@root) @g end end
node(o)
click to toggle source
Return a GraphViz::Node
object for o
. Multiple requests with the same object return the same node object.
@param o an object @return [GraphViz::Node] a node object for o
# File lib/rattler/util/graphviz/digraph_builder.rb, line 46 def node(o) @nodes.fetch(o.object_id) do new_node = @g.add_nodes new_node_name, node_options(o) @nodes[o.object_id] = new_node each_child_node_of(o) {|_| new_node << node(_) } new_node end end
Private Instance Methods
new_node_name()
click to toggle source
# File lib/rattler/util/graphviz/digraph_builder.rb, line 57 def new_node_name name = "n#{@node_serial}" @node_serial += 1 name end