Class: Stateoscope::Graph
- Inherits:
-
Object
- Object
- Stateoscope::Graph
- Defined in:
- lib/stateoscope/graph.rb
Instance Attribute Summary collapse
-
#final_states ⇒ Object
Returns the value of attribute final_states.
-
#initial_state ⇒ Object
Returns the value of attribute initial_state.
-
#states ⇒ Object
Returns the value of attribute states.
-
#transitions ⇒ Object
Returns the value of attribute transitions.
Instance Method Summary collapse
- #add_state(state) ⇒ Object
- #add_transition(from, to, event = nil) ⇒ Object
- #detect_final_states! ⇒ Object
- #final_state?(state) ⇒ Boolean
-
#initialize ⇒ Graph
constructor
A new instance of Graph.
Constructor Details
#initialize ⇒ Graph
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_states ⇒ Object
Returns the value of attribute final_states.
5 6 7 |
# File 'lib/stateoscope/graph.rb', line 5 def final_states @final_states end |
#initial_state ⇒ Object
Returns the value of attribute initial_state.
5 6 7 |
# File 'lib/stateoscope/graph.rb', line 5 def initial_state @initial_state end |
#states ⇒ Object
Returns the value of attribute states.
5 6 7 |
# File 'lib/stateoscope/graph.rb', line 5 def states @states end |
#transitions ⇒ Object
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
25 26 27 |
# File 'lib/stateoscope/graph.rb', line 25 def final_state?(state) final_states.include?(state) end |