Class: Lab42::StateMachine
- Inherits:
-
Object
- Object
- Lab42::StateMachine
- Defined in:
- lib/lab42/state_machine.rb,
lib/lab42/state_machine/dsl.rb,
lib/lab42/state_machine/state.rb,
lib/lab42/state_machine/version.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
"0.3.0"
Instance Attribute Summary collapse
-
#current ⇒ Object
Returns the value of attribute current.
-
#designation ⇒ Object
readonly
Returns the value of attribute designation.
-
#input ⇒ Object
Returns the value of attribute input.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#output ⇒ Object
Returns the value of attribute output.
-
#states ⇒ Object
readonly
Returns the value of attribute states.
Instance Method Summary collapse
- #add(state, trigger, action, new_state = nil) ⇒ Object
- #run(accumulator = nil, input = nil) ⇒ Object
Instance Attribute Details
#current ⇒ Object
Returns the value of attribute current.
6 7 8 |
# File 'lib/lab42/state_machine.rb', line 6 def current @current end |
#designation ⇒ Object (readonly)
Returns the value of attribute designation.
7 8 9 |
# File 'lib/lab42/state_machine.rb', line 7 def designation @designation end |
#input ⇒ Object
Returns the value of attribute input.
6 7 8 |
# File 'lib/lab42/state_machine.rb', line 6 def input @input end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/lab42/state_machine.rb', line 7 def @options end |
#output ⇒ Object
Returns the value of attribute output.
6 7 8 |
# File 'lib/lab42/state_machine.rb', line 6 def output @output end |
#states ⇒ Object (readonly)
Returns the value of attribute states.
7 8 9 |
# File 'lib/lab42/state_machine.rb', line 7 def states @states end |
Instance Method Details
#add(state, trigger, action, new_state = nil) ⇒ Object
10 11 12 13 |
# File 'lib/lab42/state_machine.rb', line 10 def add(state, trigger, action, new_state=nil) s = states[state] s.add(trigger, action, new_state) end |
#run(accumulator = nil, input = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/lab42/state_machine.rb', line 15 def run(accumulator=nil, input=nil) if input @input = input @input = input.enum_for(:each) unless Enumerator === input end loop do accumulator = _transition(accumulator) end accumulator end |