Class: OllamaChat::Switches::Switch
- Inherits:
-
Object
- Object
- OllamaChat::Switches::Switch
- Includes:
- CheckSwitch, PerformCallbacks
- 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:, callbacks: {}) ⇒ 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:, callbacks: {}) ⇒ Switch
Initializes a new Switch instance.
108 109 110 111 112 |
# File 'lib/ollama_chat/switches.rb', line 108 def initialize(msg:, value:, callbacks: {}) @value = !!value @msg = msg @callbacks = callbacks.to_h end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
116 117 118 |
# File 'lib/ollama_chat/switches.rb', line 116 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.
124 125 126 127 |
# File 'lib/ollama_chat/switches.rb', line 124 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.
133 134 135 136 |
# File 'lib/ollama_chat/switches.rb', line 133 def toggle(show: true) @value = !@value show && self.show end |