Class: Stateoscope::Graph

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGraph

Returns a new instance of Graph.



7
8
9
10
11
# File 'lib/stateoscope/graph.rb', line 7

def initialize
  self.states = []
  self.final_states = []
  self.transitions = []
end

Instance Attribute Details

#final_statesObject

Returns the value of attribute final_states.



5
6
7
# File 'lib/stateoscope/graph.rb', line 5

def final_states
  @final_states
end

#initial_stateObject

Returns the value of attribute initial_state.



5
6
7
# File 'lib/stateoscope/graph.rb', line 5

def initial_state
  @initial_state
end

#statesObject

Returns the value of attribute states.



5
6
7
# File 'lib/stateoscope/graph.rb', line 5

def states
  @states
end

#transitionsObject

Returns the value of attribute transitions.



5
6
7
# File 'lib/stateoscope/graph.rb', line 5

def transitions
  @transitions
end

Instance Method Details

#add_state(state) ⇒ Object



13
14
15
# File 'lib/stateoscope/graph.rb', line 13

def add_state(state)
  states << state
end

#add_transition(from, to, event = nil) ⇒ Object



17
18
19
# File 'lib/stateoscope/graph.rb', line 17

def add_transition(from, to, event = nil)
  transitions << OpenStruct.new(from: from, to: to, event: event)
end

#detect_final_states!Object



21
22
23
# File 'lib/stateoscope/graph.rb', line 21

def detect_final_states!
  self.final_states = states - transitions.map(&:from)
end

#final_state?(state) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/stateoscope/graph.rb', line 25

def final_state?(state)
  final_states.include?(state)
end