Class: StatesLanguageMachine::State
- Inherits:
-
Object
- Object
- StatesLanguageMachine::State
- Defined in:
- lib/ruby_slm/state.rb
Overview
Base state class that provides common functionality for all states
Direct Known Subclasses
Instance Attribute Summary collapse
-
#end_state ⇒ Boolean
readonly
Whether this is an end state.
-
#name ⇒ String
readonly
The name of the state.
-
#next_state ⇒ String?
readonly
The next state name.
-
#type ⇒ String
readonly
The type of the state.
Instance Method Summary collapse
-
#end_state? ⇒ Boolean
Whether this state is an end state.
-
#execute(execution, input) ⇒ Hash
Execute the state (to be implemented by subclasses).
-
#initialize(name, definition) ⇒ State
constructor
A new instance of State.
-
#next_state_name(input = nil) ⇒ String?
Get the next state name (can be overridden by subclasses that need input).
Constructor Details
#initialize(name, definition) ⇒ State
Returns a new instance of State.
17 18 19 20 21 22 23 |
# File 'lib/ruby_slm/state.rb', line 17 def initialize(name, definition) @name = name @type = definition["Type"] @next_state = definition["Next"] @end_state = definition.key?("End") && definition["End"] @definition = definition end |
Instance Attribute Details
#end_state ⇒ Boolean (readonly)
Returns whether this is an end state.
13 14 15 |
# File 'lib/ruby_slm/state.rb', line 13 def end_state @end_state end |
#name ⇒ String (readonly)
Returns the name of the state.
7 8 9 |
# File 'lib/ruby_slm/state.rb', line 7 def name @name end |
#next_state ⇒ String? (readonly)
Returns the next state name.
11 12 13 |
# File 'lib/ruby_slm/state.rb', line 11 def next_state @next_state end |
#type ⇒ String (readonly)
Returns the type of the state.
9 10 11 |
# File 'lib/ruby_slm/state.rb', line 9 def type @type end |
Instance Method Details
#end_state? ⇒ Boolean
Returns whether this state is an end state.
34 35 36 |
# File 'lib/ruby_slm/state.rb', line 34 def end_state? @end_state end |
#execute(execution, input) ⇒ Hash
Execute the state (to be implemented by subclasses)
43 44 45 |
# File 'lib/ruby_slm/state.rb', line 43 def execute(execution, input) raise NotImplementedError, "Subclasses must implement execute method" end |
#next_state_name(input = nil) ⇒ String?
Get the next state name (can be overridden by subclasses that need input)
28 29 30 31 |
# File 'lib/ruby_slm/state.rb', line 28 def next_state_name(input = nil) return nil if end_state? @next_state end |