Class: OllamaChat::Switches::Switch

Inherits:
Object
  • Object
show all
Includes:
CheckSwitch
Defined in:
lib/ollama_chat/switches.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CheckSwitch

#off?, #show

Constructor Details

#initialize(name, msg:, config:) ⇒ Switch

Returns a new instance of Switch.



19
20
21
22
# File 'lib/ollama_chat/switches.rb', line 19

def initialize(name, msg:, config:)
  @value = [ false, true ].include?(config) ? config : !!config.send("#{name}?")
  @msg   = msg
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



24
25
26
# File 'lib/ollama_chat/switches.rb', line 24

def value
  @value
end

Instance Method Details

#set(value, show: false) ⇒ Object



26
27
28
29
# File 'lib/ollama_chat/switches.rb', line 26

def set(value, show: false)
  @value = !!value
  show && self.show
end

#toggle(show: true) ⇒ Object



31
32
33
34
# File 'lib/ollama_chat/switches.rb', line 31

def toggle(show: true)
  @value = !@value
  show && self.show
end