Class: Lab42::Core::StateMachine::Transition
- Defined in:
- lib/lab42/core/state_machine/transition.rb
Instance Attribute Summary collapse
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
-
#matcher_arity ⇒ Object
readonly
Returns the value of attribute matcher_arity.
-
#next_state ⇒ Object
readonly
Returns the value of attribute next_state.
Instance Method Summary collapse
-
#initialize(next_state, matcher) ⇒ Transition
constructor
A new instance of Transition.
- #match(line, idx, handler) ⇒ Object
Constructor Details
#initialize(next_state, matcher) ⇒ Transition
Returns a new instance of Transition.
8 9 10 11 |
# File 'lib/lab42/core/state_machine/transition.rb', line 8 def initialize next_state, matcher @next_state = next_state @matcher = make_matcher matcher end |
Instance Attribute Details
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
7 8 9 |
# File 'lib/lab42/core/state_machine/transition.rb', line 7 def matcher @matcher end |
#matcher_arity ⇒ Object (readonly)
Returns the value of attribute matcher_arity.
7 8 9 |
# File 'lib/lab42/core/state_machine/transition.rb', line 7 def matcher_arity @matcher_arity end |
#next_state ⇒ Object (readonly)
Returns the value of attribute next_state.
7 8 9 |
# File 'lib/lab42/core/state_machine/transition.rb', line 7 def next_state @next_state end |
Instance Method Details
#match(line, idx, handler) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/lab42/core/state_machine/transition.rb', line 14 def match line, idx, handler if matcher_arity == 1 matcher.(line) else matcher.(line, idx) end.tap do | result | return Lab42::Core::StateMachine::Match.new( data: result, state: next_state, transition: self, line: line, index: idx, handler: handler ) if result return nil end end |