Class: HammerCLI::Options::Normalizers::Enum

Inherits:
AbstractNormalizer show all
Defined in:
lib/hammer_cli/options/normalizers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(allowed_values) ⇒ Enum

Returns a new instance of Enum.



226
227
228
# File 'lib/hammer_cli/options/normalizers.rb', line 226

def initialize(allowed_values)
  @allowed_values = allowed_values
end

Instance Attribute Details

#allowed_valuesObject (readonly)

Returns the value of attribute allowed_values.



224
225
226
# File 'lib/hammer_cli/options/normalizers.rb', line 224

def allowed_values
  @allowed_values
end

Instance Method Details

#complete(value) ⇒ Object



247
248
249
# File 'lib/hammer_cli/options/normalizers.rb', line 247

def complete(value)
  Completer::finalize_completions(@allowed_values)
end

#descriptionObject



230
231
232
# File 'lib/hammer_cli/options/normalizers.rb', line 230

def description
  _("Possible value(s): %s") % quoted_values
end

#format(value) ⇒ Object



234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/hammer_cli/options/normalizers.rb', line 234

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