# File lib/state_machine/machine.rb, line 1496
    def draw(options = {})
      options = {
        :name => "#{owner_class.name}_#{name}",
        :path => '.',
        :format => 'png',
        :font => 'Arial',
        :orientation => 'portrait'
      }.merge(options)
      assert_valid_keys(options, :name, :path, :format, :font, :orientation)
      
      begin
        # Load the graphviz library
        require 'rubygems'
        gem 'ruby-graphviz', '>=0.9.0'
        require 'graphviz'
        
        graph = GraphViz.new('G', :rankdir => options[:orientation] == 'landscape' ? 'LR' : 'TB')
        
        # Add nodes
        states.by_priority.each do |state|
          node = state.draw(graph)
          node.fontname = options[:font]
        end
        
        # Add edges
        events.each do |event|
          edges = event.draw(graph)
          edges.each {|edge| edge.fontname = options[:font]}
        end
        
        # Generate the graph
        graphvizVersion = Constants::RGV_VERSION.split('.')
        file = File.join(options[:path], "#{options[:name]}.#{options[:format]}")
        
        if graphvizVersion[1] == '9' && graphvizVersion[2] == '0'
          outputOptions = {:output => options[:format], :file => file}
        else
          outputOptions = {options[:format] => file}
        end
        
        graph.output(outputOptions)
        graph
      rescue LoadError
        $stderr.puts 'Cannot draw the machine. `gem install ruby-graphviz` >= v0.9.0 and try again.'
        false
      end
    end