def draw(options = {})
options = {
:name => "#{owner_class.name}_#{name}",
:path => '.',
:format => 'png',
:font => 'Arial',
:orientation => 'portrait',
:output => true
}.merge(options)
assert_valid_keys(options, :name, :path, :format, :font, :orientation, :output)
begin
require 'rubygems'
require 'graphviz'
graph = GraphViz.new('G',
:output => options[:format],
:file => File.join(options[:path], "#{options[:name]}.#{options[:format]}"),
:rankdir => options[:orientation] == 'landscape' ? 'LR' : 'TB'
)
states.by_priority.each do |state|
node = state.draw(graph)
node.fontname = options[:font]
end
events.each do |event|
edges = event.draw(graph)
edges.each {|edge| edge.fontname = options[:font]}
end
graph.output if options[:output]
graph
rescue LoadError
$stderr.puts 'Cannot draw the machine. `gem install ruby-graphviz` and try again.'
false
end
end