Module: Lab42::Core::StateMachine
- Defined in:
- lib/lab42/core/state_machine.rb
Defined Under Namespace
Modules: ClassMethods, Tools Classes: Match, Transition
Constant Summary collapse
Instance Attribute Summary collapse
-
#current_state ⇒ Object
readonly
Returns the value of attribute current_state.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#current_state ⇒ Object (readonly)
Returns the value of attribute current_state.
7 8 9 |
# File 'lib/lab42/core/state_machine.rb', line 7 def current_state @current_state end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
7 8 9 |
# File 'lib/lab42/core/state_machine.rb', line 7 def object @object end |
Class Method Details
.included(into) ⇒ Object
9 10 11 |
# File 'lib/lab42/core/state_machine.rb', line 9 def self.included into into.extend ClassMethods end |
Instance Method Details
#run(input) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/lab42/core/state_machine.rb', line 13 def run input input.each_with_index do |line, idx| match = __handlers__[current_state].find_with_value{ |t, h| t.match line, idx, h } next unless match __run_handler__ match @current_state = match.state end __after_last__ object end |