class HammerCLI::Options::Normalizers::Enum

Attributes

allowed_values[R]

Public Class Methods

new(allowed_values) click to toggle source
# File lib/hammer_cli/options/normalizers.rb, line 176
def initialize(allowed_values)
  @allowed_values = allowed_values
end

Public Instance Methods

complete(value) click to toggle source
# File lib/hammer_cli/options/normalizers.rb, line 197
def complete(value)
  Completer::finalize_completions(@allowed_values)
end
description() click to toggle source
# File lib/hammer_cli/options/normalizers.rb, line 180
def description
  _("Possible value(s): %s") % quoted_values
end
format(value) click to toggle source
# File lib/hammer_cli/options/normalizers.rb, line 184
def format(value)
  if @allowed_values.include? value
    value
  else
    if allowed_values.count == 1
      msg = _("Value must be %s.") % quoted_values
    else
      msg = _("Value must be one of %s.") % quoted_values
    end
    raise ArgumentError, msg
  end
end

Private Instance Methods

quoted_values() click to toggle source
# File lib/hammer_cli/options/normalizers.rb, line 203
def quoted_values
  @allowed_values.map { |v| "'#{v}'" }.join(', ')
end