Class: Stateful::State
- Inherits:
-
Object
- Object
- Stateful::State
- Defined in:
- lib/Stateful/State.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#transitions ⇒ Object
Returns the value of attribute transitions.
Instance Method Summary collapse
- #event(event) ⇒ Object (also: #on)
-
#initialize(name, options = {}) ⇒ State
constructor
A new instance of State.
- #next_state_name(event_name) ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ State
Returns a new instance of State.
13 14 15 16 17 |
# File 'lib/Stateful/State.rb', line 13 def initialize(name, = {}) @name = name @options = @transitions = [] end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/Stateful/State.rb', line 10 def name @name end |
#transitions ⇒ Object
Returns the value of attribute transitions.
11 12 13 |
# File 'lib/Stateful/State.rb', line 11 def transitions @transitions end |
Instance Method Details
#event(event) ⇒ Object Also known as: on
19 20 21 22 23 24 |
# File 'lib/Stateful/State.rb', line 19 def event(event) event_name, new_state = event.keys.first, event.values.first transitions << Transition.new(event_name, new_state) transitions.shuffle if non_deterministic_event_ordering? transitions end |
#next_state_name(event_name) ⇒ Object
27 28 29 30 31 |
# File 'lib/Stateful/State.rb', line 27 def next_state_name(event_name) if matching_transition = transitions.detect{|transition| transition.event_name == event_name} matching_transition.next_state_name end end |