Class: DiagramGraph

Inherits:
Object
  • Object
show all
Defined in:
lib/railroad/diagram_graph.rb

Overview

RailRoad diagram structure

Instance Method Summary collapse

Constructor Details

#initializeDiagramGraph

Returns a new instance of DiagramGraph.



11
12
13
14
15
16
# File 'lib/railroad/diagram_graph.rb', line 11

def initialize
  @diagram_type = ''
  @show_label = false
  @nodes = []
  @edges = []
end

Instance Method Details

#add_edge(edge) ⇒ Object



22
23
24
# File 'lib/railroad/diagram_graph.rb', line 22

def add_edge(edge)
  @edges << edge
end

#add_node(node) ⇒ Object



18
19
20
# File 'lib/railroad/diagram_graph.rb', line 18

def add_node(node)
  @nodes << node
end

#diagram_type=(type) ⇒ Object



26
27
28
# File 'lib/railroad/diagram_graph.rb', line 26

def diagram_type= (type)
  @diagram_type = type
end

#show_label=(value) ⇒ Object



30
31
32
# File 'lib/railroad/diagram_graph.rb', line 30

def show_label= (value)
  @show_label = value
end

#to_dotObject

Generate DOT graph



36
37
38
39
40
41
# File 'lib/railroad/diagram_graph.rb', line 36

def to_dot
  return dot_header +
         @nodes.map{|n| dot_node *n}.join +
         @edges.map{|e| dot_edge *e}.join +
         dot_footer
end

#to_xmiObject

Generate XMI diagram (not yet implemented)



44
45
46
47
# File 'lib/railroad/diagram_graph.rb', line 44

def to_xmi
   STDERR.print "Sorry. XMI output not yet implemented.\n\n"
   return ""
end

#to_yumlObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/railroad/diagram_graph.rb', line 48

def to_yuml
    classes={}
    parts=[]
    parts<<@nodes.collect{|node| 
      type=node[0]
      name=node[1]
      attributes=node[2]
      case type
        when 'model'
             "[#{name}|#{attributes.join(';')}|#{methods.join(';')}]"
        else
           "[#{name}]"  
      end
    }
    parts<<@edges.collect{|edge|
      type=edge[0]
      from=edge[1]
      to=edge[2]
      name=edge[3]
      from_edg=edge[4]
      to_edg=edge[5]
      association=case type
        when 'is-a'
             "^-"
        else 
          yuml_association(from_edg,to_edg)
        #when 'event'
        #     options += "fontsize=10"
      end
      "[#{from}]#{association}[#{to}]"
    }
    parts.join(",")
end