Class: Rattler::Util::GraphViz::DigraphBuilder
- Inherits:
-
Object
- Object
- Rattler::Util::GraphViz::DigraphBuilder
- Includes:
- NodeBuilder
- Defined in:
- lib/rattler/util/graphviz/digraph_builder.rb
Overview
DigraphBuilder
is used to build GraphViz objects representing trees of nodes.
Class Method Summary collapse
-
.digraph(root, name = 'G') ⇒ Object
A new
GraphViz
digraph object representingroot
.
Instance Method Summary collapse
-
#digraph ⇒ Object
A new
GraphViz
digraph object representing the root object. -
#initialize(root, name = 'G') ⇒ DigraphBuilder
constructor
Create a new digraph builder for
root
. -
#node(o) ⇒ GraphViz::Node
Return a
GraphViz::Node
object foro
.
Methods included from NodeBuilder
#array_like?, #each_child_node_of, #node_label, #node_options, #node_shape, #record_like?
Constructor Details
#initialize(root, name = 'G') ⇒ DigraphBuilder
Create a new digraph builder for root
.
26 27 28 29 30 31 |
# 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 |
Class Method Details
Instance Method Details
#digraph ⇒ Object
Returns a new GraphViz
digraph object representing the root object.
34 35 36 37 38 39 |
# File 'lib/rattler/util/graphviz/digraph_builder.rb', line 34 def digraph @digraph ||= begin node(@root) @g end end |
#node(o) ⇒ GraphViz::Node
Return a GraphViz::Node
object for o
. Multiple requests with the same object return the same node object.
46 47 48 49 50 51 52 53 |
# 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, (o) @nodes[o.object_id] = new_node each_child_node_of(o) {|_| new_node << node(_) } new_node end end |