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 feedback when the state changes.
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
The value reader returns the current value of the attribute.
Instance Method Summary collapse
-
#initialize(msg:, value:) ⇒ Switch
constructor
The initialize method sets up the switch with a default value and message.
-
#set(value, show: false) ⇒ Object
The set method assigns a boolean value to the instance variable @value and optionally displays it.
-
#toggle(show: true) ⇒ Object
The toggle method switches the current value of the instance variable and optionally displays it.
Methods included from CheckSwitch
Constructor Details
#initialize(msg:, value:) ⇒ Switch
The initialize method sets up the switch with a default value and message.
67 68 69 70 |
# File 'lib/ollama_chat/switches.rb', line 67 def initialize(msg:, value:) @value = !!value @msg = msg end |
Instance Attribute Details
#value ⇒ Object (readonly)
The value reader returns the current value of the attribute.
73 74 75 |
# File 'lib/ollama_chat/switches.rb', line 73 def value @value end |
Instance Method Details
#set(value, show: false) ⇒ Object
The set method assigns a boolean value to the instance variable @value and optionally displays it.
82 83 84 85 |
# File 'lib/ollama_chat/switches.rb', line 82 def set(value, show: false) @value = !!value show && self.show end |
#toggle(show: true) ⇒ Object
The toggle method switches the current value of the instance variable and optionally displays it.
92 93 94 95 |
# File 'lib/ollama_chat/switches.rb', line 92 def toggle(show: true) @value = !@value show && self.show end |