Class: NxtStateMachine::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/nxt_state_machine/graph.rb

Instance Method Summary collapse

Constructor Details

#initialize(state_machines, **options) ⇒ Graph

Returns a new instance of Graph.



3
4
5
6
# File 'lib/nxt_state_machine/graph.rb', line 3

def initialize(state_machines, **options)
  @state_machines = state_machines
  @options = default_options.merge(**options)
end

Instance Method Details

#drawObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/nxt_state_machine/graph.rb', line 8

def draw
  require 'ruby-graphviz'

  state_machines.each do |_, state_machine|
    add_nodes(state_machine)
    add_edges(state_machine)
  end

  filename = File.join(options[:path], "#{options[:name]}.#{options[:format]}")

  graph.output options[:format] => filename

  puts '----------------------------------------------'
  puts 'Please run the following to open the generated file:'
  puts "open '#{filename}'"
  puts '----------------------------------------------'

  graph
end