Module: AskTTY::Internal::Options

Defined in:
lib/asktty/internal/options.rb

Defined Under Namespace

Classes: Option

Class Method Summary collapse

Class Method Details

.normalize(options) ⇒ Object

Raises:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/asktty/internal/options.rb', line 10

def normalize(options)
  raise AskTTY::Error, "options must not be empty" if options.nil? || options.empty?

  options.map do |option|
    next option if option.is_a?(Option)

    raise AskTTY::Error, "options must be hashes with label and value" unless option.is_a?(Hash)

    label = option[:label] || option["label"]
    has_value = option.key?(:value) || option.key?("value")
    value = option[:value] if option.key?(:value)
    value = option["value"] if option.key?("value")

    raise AskTTY::Error, "options must include label and value" unless label && has_value

    Option.new(label.to_s, value)
  end
end

.values(options) ⇒ Object



29
30
31
# File 'lib/asktty/internal/options.rb', line 29

def values(options)
  options.map(&:value)
end