Class: Lab42::Core::StateMachine::Transition

Inherits:
Object
  • Object
show all
Defined in:
lib/lab42/core/state_machine/transition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#matcherObject (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_arityObject (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_stateObject (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