Class: OllamaChat::StateSelectors::StateSelector
- Inherits:
-
Object
- Object
- OllamaChat::StateSelectors::StateSelector
- Includes:
- Common
- Defined in:
- lib/ollama_chat/state_selectors.rb
Overview
A state selector that manages configurable states with selection and display capabilities.
Instance Attribute Summary collapse
-
#selected ⇒ Object
The selected reader returns the currently selected state of the switch.
Attributes included from Common
#allow_empty, #default, #name, #off, #states
Attributes included from Utils::Chooser
#current_search_state Stores the
Instance Method Summary collapse
-
#initialize(name:, states:, default: nil, off: nil, allow_empty: false) ⇒ StateSelector
constructor
Initializes a new StateSelector with the given configuration.
Methods included from Common
#allow_empty?, #choose, #off?, #on?, #show, #to_s
Methods included from Utils::Chooser
#choose_entry, #choose_with_state
Constructor Details
#initialize(name:, states:, default: nil, off: nil, allow_empty: false) ⇒ StateSelector
Initializes a new StateSelector with the given configuration.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/ollama_chat/state_selectors.rb', line 132 def initialize(name:, states:, default: nil, off: nil, allow_empty: false) @name = name.to_s @states = Set.new(states.map(&:to_s)) @allow_empty = allow_empty unless allow_empty states.empty? and raise ArgumentError, 'states cannot be empty' end if default @default = default.to_s unless allow_empty? states.member?(@default) or raise ArgumentError, "default has to be one of #{states.to_a * ', '}." end @selected = @default else @selected = states.first end @off = Array(off) end |
Instance Attribute Details
#selected ⇒ Object
The selected reader returns the currently selected state of the switch.
155 156 157 |
# File 'lib/ollama_chat/state_selectors.rb', line 155 def selected @selected end |