Class: StateShifter::Draw

Inherits:
Object
  • Object
show all
Defined in:
lib/state_shifter/draw.rb

Class Method Summary collapse

Class Method Details

.graph(klasses, options) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/state_shifter/draw.rb', line 8

def self.graph klasses, options
  klasses.split(',').each do |klass|
    this_class = eval(klass)

    graph = GraphViz.new(:G, :rankdir => options[:orientation] == 'landscape' ? 'LR' : 'TB')

    this_class.state_machine_definition.states.each do |state_name, state_definition|
      node = state_definition.draw(graph, options)
      node.fontname = options[:font] if options[:font]
    end

    this_class.state_machine_definition.events.each do |event_name, event_definition|
      edge = event_definition.draw(graph, options)
      edge.fontname = options[:font] if options[:font]
    end

    graphvizVersion = Constants::RGV_VERSION.split('.')

    if graphvizVersion[0] == '0' && graphvizVersion[1] == '9' && graphvizVersion[2] == '0'
      output_options = {:output => options[:format], :file => options[:output_filename]}
    else
      output_options = {options[:format] => options[:output_filename]}
    end

    graph.output(output_options)
  end
end