Class: OllamaChat::Switches::Switch
- Inherits:
-
Object
- Object
- OllamaChat::Switches::Switch
- Includes:
- CheckSwitch
- Defined in:
- lib/ollama_chat/switches.rb
Overview
A switch class that manages boolean state with toggle and set functionality.
The Switch class provides a simple way to manage boolean configuration options with methods to toggle, set, and query the current state. It includes messaging capabilities to provide a message when the state changes.
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(msg:, value:) ⇒ Switch
constructor
Initializes a new Switch instance.
-
#set(value, show: false, output: STDOUT) ⇒ String, ...
Assigns a boolean value to the switch and optionally displays the result.
-
#toggle(show: true) ⇒ String, ...
Toggles the current boolean value and optionally displays the result.
Methods included from CheckSwitch
Constructor Details
#initialize(msg:, value:) ⇒ Switch
Initializes a new Switch instance.
65 66 67 68 |
# File 'lib/ollama_chat/switches.rb', line 65 def initialize(msg:, value:) @value = !!value @msg = msg end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
72 73 74 |
# File 'lib/ollama_chat/switches.rb', line 72 def value @value end |
Instance Method Details
#set(value, show: false, output: STDOUT) ⇒ String, ...
Assigns a boolean value to the switch and optionally displays the result.
80 81 82 83 |
# File 'lib/ollama_chat/switches.rb', line 80 def set(value, show: false, output: STDOUT) @value = !!value show && self.show(output:) end |
#toggle(show: true) ⇒ String, ...
Toggles the current boolean value and optionally displays the result.
89 90 91 92 |
# File 'lib/ollama_chat/switches.rb', line 89 def toggle(show: true) @value = !@value show && self.show end |