class TTY::Prompt::Choices
@api private
A class responsible for storing a collection of choices
def self.[](*choices)
- Api: - public
Returns:
-
(Choices)
-
Parameters:
-
choices
(Array[Object]
) --
def self.[](*choices) new(choices) end
def <<(choice)
- Api: - public
Parameters:
-
choice
(Object
) --
def <<(choice) choices << Choice.from(choice) end
def [](index)
- Api: - public
Returns:
-
(Choice)
-
Parameters:
-
index
(Integer
) --
def [](index) @choices[index] end
def each(&block)
- Api: - public
Other tags:
- Yield: -
def each(&block) return to_enum unless block_given? choices.each(&block) end
def enabled
- Api: - public
def enabled reject(&:disabled?) end
def enabled_indexes
def enabled_indexes each_with_index.reduce([]) do |acc, (choice, idx)| acc << idx unless choice.disabled? acc end end
def find_by(attr, value)
- Api: - public
Returns:
-
(Choice)
-
Parameters:
-
value
(Object
) -- -
attr
(Symbol
) --
def find_by(attr, value) find { |choice| choice.public_send(attr) == value } end
def initialize(choices = [])
- Api: - public
Parameters:
-
choices
(Array[Choice]
) --
def initialize(choices = []) @choices = choices.map do |choice| Choice.from(choice) end end
def pluck(name)
- Api: - public
Returns:
-
(Choice)
-
Parameters:
-
name
(String
) --
def pluck(name) map { |choice| choice.public_send(name) } end