Class: StatesLanguageMachine::States::Choice
- Inherits:
-
Base
- Object
- StatesLanguageMachine::State
- Base
- StatesLanguageMachine::States::Choice
- Defined in:
- lib/ruby_slm/states/choice.rb
Instance Attribute Summary collapse
-
#choices ⇒ Object
readonly
Returns the value of attribute choices.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
Attributes inherited from Base
Attributes inherited from StatesLanguageMachine::State
#end_state, #name, #next_state, #type
Instance Method Summary collapse
- #execute(execution, input) ⇒ Object
-
#initialize(name, definition) ⇒ Choice
constructor
A new instance of Choice.
- #next_state_name(input = nil) ⇒ Object
Methods inherited from StatesLanguageMachine::State
Constructor Details
#initialize(name, definition) ⇒ Choice
Returns a new instance of Choice.
8 9 10 11 12 13 |
# File 'lib/ruby_slm/states/choice.rb', line 8 def initialize(name, definition) super @choices = definition["Choices"] || [] @default = definition["Default"] @evaluated_next_state = nil end |
Instance Attribute Details
#choices ⇒ Object (readonly)
Returns the value of attribute choices.
6 7 8 |
# File 'lib/ruby_slm/states/choice.rb', line 6 def choices @choices end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
6 7 8 |
# File 'lib/ruby_slm/states/choice.rb', line 6 def default @default end |
Instance Method Details
#execute(execution, input) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/ruby_slm/states/choice.rb', line 15 def execute(execution, input) execution.logger&.info("Executing choice state: #{@name}") @evaluated_next_state = evaluate_choices(input, execution.logger) execution.logger&.info("Selected next state: #{@evaluated_next_state}") process_result(execution, input) input end |
#next_state_name(input = nil) ⇒ Object
25 26 27 28 29 |
# File 'lib/ruby_slm/states/choice.rb', line 25 def next_state_name(input = nil) return nil if end_state? return @evaluated_next_state if @evaluated_next_state input ? evaluate_choices(input) : @default end |