class DiagramGraph
PrailRoady
diagram structure
Attributes
alphabetize[W]
diagram_type[W]
show_label[W]
Public Class Methods
new()
click to toggle source
# File lib/prailroady/diagram_graph.rb, line 9 def initialize @diagram_type = '' @show_label = false @alphabetize = false @nodes = [] @edges = [] end
Public Instance Methods
add_edge(edge)
click to toggle source
# File lib/prailroady/diagram_graph.rb, line 21 def add_edge(edge) @edges << edge end
add_node(node)
click to toggle source
# File lib/prailroady/diagram_graph.rb, line 17 def add_node(node) @nodes << node end
to_dot()
click to toggle source
Generate DOT graph
# File lib/prailroady/diagram_graph.rb, line 32 def to_dot dot_header + @nodes.map { |n| dot_node n[0], n[1], n[2], n[3] }.join + @edges.map { |e| dot_edge e[0], e[1], e[2], e[3] }.join + dot_footer end
to_xmi()
click to toggle source
Generate XMI diagram (not yet implemented)
# File lib/prailroady/diagram_graph.rb, line 40 def to_xmi STDERR.print "Sorry. XMI output not yet implemented.\n\n" '' end
Private Instance Methods
dot_edge(type, from, to, name = '')
click to toggle source
Build a DOT graph edge
# File lib/prailroady/diagram_graph.rb, line 98 def dot_edge(type, from, to, name = '') ret = "" case type when 'one-one' ret = "\t#{quote(from)} -- #{quote(to)}\n" when 'one-many' ret = "\t#{quote(from)} --|{ #{quote(to)}\n" when 'many-many' ret = "\t#{quote(from)} }|--|{ #{quote(to)}\n" when 'belongs-to' ret = "\t#{quote(from)} }|--|{ #{quote(to)}\n" when 'is-a' ret = "\t#{quote(from)} }|--|{ #{quote(to)}\n" when 'event' ret = "\t#{quote(from)} }|--|{ #{quote(to)}\n" end ret end
dot_header()
click to toggle source
Build DOT diagram header
# File lib/prailroady/diagram_graph.rb, line 48 def dot_header result = "@startuml\n" result += "\tskinparam linetype ortho\n" result += "\tskinparam packageStyle rectangle\n" result += "\tskinparam shadowing false\n" result += "\tskinparam class {\n" result += "\t\tBackgroundColor White\n" result += "\t\tBorderColor Black\n" result += "\t\tArrowColor Black\n" result += "\t}\n" result += "\thide members\n" if !@show_label result += "\thide circle\n" result end
dot_node(type, name, attributes = nil, custom_options = '')
click to toggle source
Build a DOT graph node
# File lib/prailroady/diagram_graph.rb, line 69 def dot_node(type, name, attributes = nil, custom_options = '') options = '' case type when 'model' options += attributes.sort_by { |s| @alphabetize ? s : nil }.map{|s| "\t\t#{s}"}.join("\n") when 'model-brief' options += "" when 'class' options += "" when 'class-brief' options += "" when 'controller' options += "" options += attributes[:public].sort_by { |s| @alphabetize ? s : nil }.map{|s| "\t\t#{s}"}.join("\n") options += attributes[:protected].sort_by { |s| @alphabetize ? s : nil }.map{|s| "\t\t#{s}"}.join("\n") options += attributes[:private].sort_by { |s| @alphabetize ? s : nil }.map{|s| "\t\t#{s}"}.join("\n") when 'controller-brief' options += "" when 'module' options += "" when 'aasm' return "aasm: \\n #{attributes.join("\\n")}" end # options = [options, custom_options].compact.reject{|o| o.empty?}.join(', ') attr_options = "{\n#{options}\n\t}" if @show_label && options.length > 0 return "\tclass #{quote(name)} as #{noquote(name)} #{attr_options}\n" end
noquote(name)
click to toggle source
# File lib/prailroady/diagram_graph.rb, line 121 def noquote(name) name.to_s.gsub(":","") end
quote(name)
click to toggle source
Quotes a class name
# File lib/prailroady/diagram_graph.rb, line 118 def quote(name) ('"' + name.to_s + '"').gsub(":","") end