Module: StonePath::Dot

Defined in:
lib/stonepath/dot.rb

Instance Method Summary collapse

Instance Method Details

#to_dotObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/stonepath/dot.rb', line 4

def to_dot
  dot = ""
  
  dot << "digraph x {\n"
  dot << "\trankdir=LR\n"
  dot << "\tnode [fontname=Helvetica,fontcolor=blue]\n"
  aasm_states.each do |state|
    dot << "\t#{state.name.to_s.camelize.singularize}\n"
  end
  
  dot << "\tedge [fontname=Helvetica,fontsize=10]\n"
  aasm_events.each do |name, event|
    event.all_transitions.each do |t|
      from = t.opts[:from].to_s.camelize.singularize
      to = t.opts[:to].to_s.camelize.singularize
      if from == to
        extras = "headport=e tailport=s]"
      else
        extras = ""
      end
      dot << "\t#{from} -> #{to} [label=\"#{name.to_s.humanize}\" arrowhead=vee"
      dot << extras
      dot << "]\n"
    end
  end
  dot << "}\n"
  dot
end