Class: Automata::StateDiagram
- Inherits:
-
Object
- Object
- Automata::StateDiagram
- Defined in:
- lib/automata/state_diagram.rb
Overview
A generic state diagram class represented as a 5-tuple.
Instance Attribute Summary collapse
-
#accept ⇒ Object
Returns the value of attribute accept.
-
#alphabet ⇒ Object
Returns the value of attribute alphabet.
-
#start ⇒ Object
Returns the value of attribute start.
-
#states ⇒ Object
Returns the value of attribute states.
-
#transitions ⇒ Object
Returns the value of attribute transitions.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ StateDiagram
constructor
Initialize and build a StateDiagram object.
Constructor Details
#initialize(params = {}) ⇒ StateDiagram
Note:
The :transitions hash structure will vary Different machines will require different transition structures. Please refer to the wiki for details regarding each machine type.
Initialize and build a StateDiagram object.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/automata/state_diagram.rb', line 23 def initialize(params={}) yaml = {} yaml = YAML::load_file(params[:file]) if params.has_key? :file @states = yaml['states'] || params[:states] @alphabet = yaml['alphabet'] || params[:alphabet] @start = yaml['start'] || params[:start] @accept = yaml['accept'] || params[:accept] @transitions = yaml['transitions'] || params[:transitions] @transitions = Hash.keys_to_strings(@transitions) end |
Instance Attribute Details
#accept ⇒ Object
Returns the value of attribute accept.
4 5 6 |
# File 'lib/automata/state_diagram.rb', line 4 def accept @accept end |
#alphabet ⇒ Object
Returns the value of attribute alphabet.
4 5 6 |
# File 'lib/automata/state_diagram.rb', line 4 def alphabet @alphabet end |
#start ⇒ Object
Returns the value of attribute start.
4 5 6 |
# File 'lib/automata/state_diagram.rb', line 4 def start @start end |
#states ⇒ Object
Returns the value of attribute states.
4 5 6 |
# File 'lib/automata/state_diagram.rb', line 4 def states @states end |
#transitions ⇒ Object
Returns the value of attribute transitions.
4 5 6 |
# File 'lib/automata/state_diagram.rb', line 4 def transitions @transitions end |