Class: Nfa2Dfa::State

Inherits:
Object
  • Object
show all
Defined in:
lib/state.rb

Overview

State of automaton

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ State

Returns a new instance of State.



9
10
11
12
13
14
15
# File 'lib/state.rb', line 9

def initialize(id)
  @id = id
  @is_final = false
  @transitions = []
  @graphviz_init = false
  @is_starting = false
end

Instance Attribute Details

#graphviz_nodeObject (readonly)

Returns the value of attribute graphviz_node.



7
8
9
# File 'lib/state.rb', line 7

def graphviz_node
  @graphviz_node
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/state.rb', line 7

def id
  @id
end

#is_finalObject (readonly)

Returns the value of attribute is_final.



7
8
9
# File 'lib/state.rb', line 7

def is_final
  @is_final
end

#is_startingObject (readonly)

Returns the value of attribute is_starting.



7
8
9
# File 'lib/state.rb', line 7

def is_starting
  @is_starting
end

Instance Method Details

#add_transition(tr) ⇒ Object



43
44
45
# File 'lib/state.rb', line 43

def add_transition(tr)
  @transitions.insert(@transitions.size, tr)
end

#associate_transitions(all_transitions) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/state.rb', line 51

def associate_transitions(all_transitions)
  @transitions.clear
  @id.split(',').each do |id_part|
    all_transitions.each do |transition|
      if id_part == transition.beginning_state.id
        add_transition(transition)
      end
    end
  end
end

#clear_transitionsObject



47
48
49
# File 'lib/state.rb', line 47

def clear_transitions
  @transitions.clear
end

#finalizeObject



39
40
41
# File 'lib/state.rb', line 39

def finalize
  @is_final = true
end

#get_next(char) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/state.rb', line 62

def get_next(char)
  ret_val = []
  @transitions.each do |trans|
    if trans.alphabet == char
      ret_val.insert(ret_val.size, trans.ending_state)
    end
  end
  ret_val
end

#graph_idObject



25
26
27
# File 'lib/state.rb', line 25

def graph_id
  is_starting ? (@id + '/init') : @id
end

#to_graph_node(viz_graph) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/state.rb', line 29

def to_graph_node(viz_graph)
  if @is_final
    @graphviz_node = viz_graph.add_nodes(
      graph_id, :shape => 'doublecircle')
  else
    @graphviz_node = viz_graph.add_nodes(graph_id, :shape => 'circle')
  end
  @graphviz_init = false
end

#to_sObject



21
22
23
# File 'lib/state.rb', line 21

def to_s
  @id.to_s
end

#to_starting_nodeObject



17
18
19
# File 'lib/state.rb', line 17

def to_starting_node
  @is_starting = true
end