Class: Graphviz::Diagram::ClassDiagram
- Inherits:
-
Object
- Object
- Graphviz::Diagram::ClassDiagram
show all
- Defined in:
- lib/graphviz/diagram/class_diagram.rb
Overview
Defined Under Namespace
Classes: Aggragation, Composition, Entity, Generalization, Link, Realization
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(opts = {}) ⇒ ClassDiagram
All ‘opts` are passed to the constructor of `GraphViz`
164
165
166
167
168
169
|
# File 'lib/graphviz/diagram/class_diagram.rb', line 164
def initialize(opts = {})
opts[:type] ||= :digraph
opts[:rankdir] ||= 'LR'
@graphviz = GraphViz.new :G, opts
@entities, @links = [], []
end
|
Instance Attribute Details
#graphviz ⇒ Object
Returns the value of attribute graphviz.
9
10
11
|
# File 'lib/graphviz/diagram/class_diagram.rb', line 9
def graphviz
@graphviz
end
|
Instance Method Details
#<<(obj) ⇒ Object
171
172
173
174
175
176
177
178
|
# File 'lib/graphviz/diagram/class_diagram.rb', line 171
def <<(obj)
case obj
when Link then @links << obj
when Entity then @entities << obj
else
fail "unknown type #{obj.class}, can not add to graph"
end
end
|
#[](name) ⇒ Object
189
190
191
192
|
# File 'lib/graphviz/diagram/class_diagram.rb', line 189
def [](name)
add_entity(name) unless entity(name)
entity(name)
end
|
#add_entity(name, opts = {}) ⇒ Object
180
181
182
|
# File 'lib/graphviz/diagram/class_diagram.rb', line 180
def add_entity(name, opts = {})
self << Entity.new(name, opts)
end
|
#entity(name) ⇒ Object
184
185
186
187
|
# File 'lib/graphviz/diagram/class_diagram.rb', line 184
def entity(name)
@entities.each { |e| return e if e.name == name }
nil
end
|
#output(hsh) ⇒ Object
194
195
196
197
198
199
200
201
202
203
204
205
|
# File 'lib/graphviz/diagram/class_diagram.rb', line 194
def output(hsh)
@entities.each do |e|
attrs = { label: e.label }.merge(e.node_attributes)
@graphviz.add_node(e.name, attrs)
end
@links.each do |l|
@graphviz.add_edges(l.from.name, l.to.name, l.attributes)
end
@graphviz.output hsh
end
|