Sha256: 502a119a0917d2f625edebdb0355ba95ffc4ada7f107c3c45ea5626c4998b48b

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

module StateShifter

  class Draw

    gem 'ruby-graphviz', '>=0.9.0'
    require 'graphviz'

    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
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
state_shifter-1.1.3 lib/state_shifter/draw.rb
state_shifter-1.1.2 lib/state_shifter/draw.rb
state_shifter-1.0.7 lib/state_shifter/draw.rb
state_shifter-1.0.5 lib/state_shifter/draw.rb
state_shifter-1.0.3 lib/state_shifter/draw.rb