Class: OllamaChat::StateSelectors::StateSelector

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/ollama_chat/state_selectors.rb

Overview

A state selector that manages configurable states with selection and display capabilities.

Constant Summary

Constants included from Feedback

Feedback::PREFIXES

Instance Attribute Summary collapse

Attributes included from Common

#allow_empty, #default, #name, #off, #states

Attributes included from Utils::Chooser

#current_search_state Stores the

Instance Method Summary collapse

Methods included from Common

#allow_empty?, #choose, #off?, #on?, #show, #to_s

Methods included from Utils::Chooser

#choose_entry, #choose_with_state

Methods included from Feedback

#feedback

Constructor Details

#initialize(name:, states:, default: nil, off: nil, allow_empty: false) ⇒ StateSelector

Initializes a new StateSelector with the given configuration.

Parameters:

  • name (String) —

    The name of the state selector for display purposes

  • states (Array<String>) —

    The list of valid states this selector can have

  • default (String, nil) (defaults to: nil) —

    The default state to select (must be one of states)

  • off (Array<String>, nil) (defaults to: nil) —

    The list of states that should be considered "off"

Raises:

  • (ArgumentError) —

    If states is empty or default is not in states



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/ollama_chat/state_selectors.rb', line 137

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.

Returns:

  • (Object) —

    the currently selected state value



160
161
162
# File 'lib/ollama_chat/state_selectors.rb', line 160

def selected
  @selected
end