Class: Resyma::Core::TransitionTable

Inherits:
Object
  • Object
show all
Defined in:
lib/resyma/core/automaton/transition.rb

Defined Under Namespace

Classes: Candidate

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTransitionTable

Returns a new instance of TransitionTable.



9
10
11
# File 'lib/resyma/core/automaton/transition.rb', line 9

def initialize
  @table = Hash.new { |hash, key| hash[key] = [] }
end

Instance Attribute Details

#tableObject (readonly)

Returns the value of attribute table.



5
6
7
# File 'lib/resyma/core/automaton/transition.rb', line 5

def table
  @table
end

Instance Method Details

#add_transition!(from_state, matchable, to_state) ⇒ nil

Add a transition from ‘from_state` to `to_state` through `matchable`

Parameters:

Returns:

  • (nil)

    Undefined



22
23
24
25
# File 'lib/resyma/core/automaton/transition.rb', line 22

def add_transition!(from_state, matchable, to_state)
  @table[from_state].push Candidate.new(matchable, to_state)
  nil
end

#candidates(from_state) ⇒ Array<Resyma::Core::TransitionTable::Candidate>

Candidate states that has a transition starting from ‘from_state`

Parameters:

Returns:



53
54
55
# File 'lib/resyma/core/automaton/transition.rb', line 53

def candidates(from_state)
  @table[from_state]
end

#destination(from_state, value) ⇒ nil, Resyma::Core::State

Query the destination state in the table. ‘nil` will be returned if the destination is not defined

Parameters:

  • from_state (Resyma::Core::State)

    Starting state

  • value (Object)

    Value to be matched, see ‘Resyme::Core::Matchable`

Returns:



36
37
38
39
40
41
42
43
# File 'lib/resyma/core/automaton/transition.rb', line 36

def destination(from_state, value)
  @table[from_state].each do |candidate|
    if candidate.condition.match_with_value? value
      return candidate.destination
    end
  end
  nil
end