Class: Graphviz::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/graphviz/graph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = 'G', attributes = {}) ⇒ Graph

Returns a new instance of Graph.



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/graphviz/graph.rb', line 90

def initialize(name = 'G', attributes = {})
	@name = name
	
	@nodes = {}
	@edges = []
	@graphs = {}
	
	@parent = nil
	
	@attributes = attributes
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



106
107
108
# File 'lib/graphviz/graph.rb', line 106

def attributes
  @attributes
end

#edgesObject (readonly)

Returns the value of attribute edges.



103
104
105
# File 'lib/graphviz/graph.rb', line 103

def edges
  @edges
end

#graphsObject (readonly)

Returns the value of attribute graphs.



104
105
106
# File 'lib/graphviz/graph.rb', line 104

def graphs
  @graphs
end

#nodesObject (readonly)

Returns the value of attribute nodes.



102
103
104
# File 'lib/graphviz/graph.rb', line 102

def nodes
  @nodes
end

Instance Method Details

#add_node(name, attributes = {}) ⇒ Object



108
109
110
# File 'lib/graphviz/graph.rb', line 108

def add_node(name, attributes = {})
	Node.new(self, name, attributes)
end

#add_subgraph(name, attributes = {}) ⇒ Object



112
113
114
115
116
117
118
119
# File 'lib/graphviz/graph.rb', line 112

def add_subgraph(name, attributes = {})
	graph = Graph.new(name, attributes)
	
	graph.attach(self)
	@graphs[name] = graph
	
	return graph
end

#attach(parent) ⇒ Object



121
122
123
# File 'lib/graphviz/graph.rb', line 121

def attach(parent)
	@parent = parent
end

#to_dot(options = {}) ⇒ Object



125
126
127
128
129
130
131
# File 'lib/graphviz/graph.rb', line 125

def to_dot(options = {})
	buffer = StringIO.new
	
	dump_graph(buffer, "", options)
	
	return buffer.string
end