Class: Nfa2Dfa::State
- Inherits:
-
Object
- Object
- Nfa2Dfa::State
- Defined in:
- lib/state.rb
Instance Attribute Summary collapse
-
#graphviz_node ⇒ Object
readonly
Returns the value of attribute graphviz_node.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#is_final ⇒ Object
readonly
Returns the value of attribute is_final.
-
#is_starting ⇒ Object
readonly
Returns the value of attribute is_starting.
Instance Method Summary collapse
- #add_transition(tr) ⇒ Object
- #associate_transitions(all_transitions) ⇒ Object
- #clear_transitions ⇒ Object
- #finalize ⇒ Object
- #get_next(char) ⇒ Object
- #graph_id ⇒ Object
-
#initialize(id) ⇒ State
constructor
A new instance of State.
- #to_graph_node(graphviz_graph) ⇒ Object
- #to_starting_node ⇒ Object
Constructor Details
#initialize(id) ⇒ State
Returns a new instance of State.
11 12 13 14 15 16 17 |
# File 'lib/state.rb', line 11 def initialize(id) @id = id @is_final = false @transitions = Array.new @graphviz_init = false @is_starting = false end |
Instance Attribute Details
#graphviz_node ⇒ Object (readonly)
Returns the value of attribute graphviz_node.
9 10 11 |
# File 'lib/state.rb', line 9 def graphviz_node @graphviz_node end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/state.rb', line 9 def id @id end |
#is_final ⇒ Object (readonly)
Returns the value of attribute is_final.
9 10 11 |
# File 'lib/state.rb', line 9 def is_final @is_final end |
#is_starting ⇒ Object (readonly)
Returns the value of attribute is_starting.
9 10 11 |
# File 'lib/state.rb', line 9 def is_starting @is_starting end |
Instance Method Details
#add_transition(tr) ⇒ Object
40 41 42 |
# File 'lib/state.rb', line 40 def add_transition(tr) @transitions.insert(@transitions.size, tr) end |
#associate_transitions(all_transitions) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/state.rb', line 48 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_transitions ⇒ Object
44 45 46 |
# File 'lib/state.rb', line 44 def clear_transitions @transitions.clear end |
#finalize ⇒ Object
36 37 38 |
# File 'lib/state.rb', line 36 def finalize @is_final = true end |
#get_next(char) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/state.rb', line 59 def get_next(char) ret_val = Array.new @transitions.each do |trans| trans.alphabet == char ? ret_val.insert(ret_val.size, trans.ending_state) : NIL end ret_val end |
#graph_id ⇒ Object
23 24 25 |
# File 'lib/state.rb', line 23 def graph_id is_starting ? (@id + "/init") : @id end |
#to_graph_node(graphviz_graph) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/state.rb', line 27 def to_graph_node(graphviz_graph) if @is_final @graphviz_node = graphviz_graph.add_nodes(graph_id, :shape => "doublecircle") else @graphviz_node = graphviz_graph.add_nodes(graph_id, :shape => "circle") end @graphviz_init = false end |
#to_starting_node ⇒ Object
19 20 21 |
# File 'lib/state.rb', line 19 def to_starting_node @is_starting = true end |