Class: TTY::Prompt::List

Inherits:
Object show all
Defined in:
lib/kuber_kit/extensions/tty_prompt.rb

Instance Method Summary collapse

Instance Method Details

#choices(values = (not_set = true)) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/kuber_kit/extensions/tty_prompt.rb', line 7

def choices(values = (not_set = true))
  if not_set
    if !filterable? || @filter.empty?
      @choices
    else
      filter_value = sanitize_for_filter(@filter.join)
      @filter_cache[filter_value] ||= @choices.enabled.select do |choice|
        sanitize_for_filter(choice.name.to_s).include?(filter_value)
      end
    end
  else
    @filter_cache = {}
    values.each { |val| @choices << val }
  end
end

#sanitize_for_filter(value) ⇒ Object



23
24
25
26
27
# File 'lib/kuber_kit/extensions/tty_prompt.rb', line 23

def sanitize_for_filter(value)
  value
    .downcase
    .gsub(/[-_]/, '')
end