class Graphviz::Diagram::ClassDiagram
An UML class diagram
Attributes
graphviz[R]
Public Class Methods
new(opts = {})
click to toggle source
All ‘opts` are passed to the constructor of `GraphViz`
# 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
Public Instance Methods
<<(obj)
click to toggle source
# 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)
click to toggle source
# File lib/graphviz/diagram/class_diagram.rb, line 189 def [](name) add_entity(name) unless entity(name) entity(name) end
add_entity(name, opts = {})
click to toggle source
# File lib/graphviz/diagram/class_diagram.rb, line 180 def add_entity(name, opts = {}) self << Entity.new(name, opts) end
entity(name)
click to toggle source
# 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)
click to toggle source
# 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