Class: SGF::More::StateMachinePresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/sgf/more/state_machine_presenter.rb

Instance Method Summary collapse

Instance Method Details

#edgesObject



11
12
13
# File 'lib/sgf/more/state_machine_presenter.rb', line 11

def edges
  @edges ||= []
end

#nodesObject



7
8
9
# File 'lib/sgf/more/state_machine_presenter.rb', line 7

def nodes
  nodes_hash.values
end

#process(state_machine) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sgf/more/state_machine_presenter.rb', line 15

def process state_machine
  nodes_hash[state_machine.start_state.to_s] = create_node(state_machine.start_state.to_s)
  state_machine.transitions.each do |from_state, transitions|
    transitions.each do |transition|
      from_node = nodes_hash[from_state.to_s] ||= create_node(from_state.to_s)
      to_state = transition.after_state || from_state
      to_node = nodes_hash[to_state.to_s] ||= create_node(to_state.to_s)
      transition_desc = transition.description || transition.event_pattern.inspect
      edges << create_edge(from_node, to_node, transition_desc)
    end
  end
end