Class: HammerCLI::Options::Normalizers::Bool

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractNormalizer

#description, inherited

Class Method Details

.common_descriptionObject



234
235
236
# File 'lib/hammer_cli/options/normalizers.rb', line 234

def common_description
  _('One of %s') % ['true/false', 'yes/no', '1/0'].join(', ')
end

.completion_typeObject



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

def completion_type
  :boolean
end

Instance Method Details

#allowed_valuesObject



239
240
241
# File 'lib/hammer_cli/options/normalizers.rb', line 239

def allowed_values
  ['yes', 'no', 'true', 'false', '1', '0']
end

#complete(value) ⇒ Object



254
255
256
# File 'lib/hammer_cli/options/normalizers.rb', line 254

def complete(value)
  allowed_values.map { |v| v + ' ' }
end

#completion_typeObject



258
259
260
# File 'lib/hammer_cli/options/normalizers.rb', line 258

def completion_type
  super.merge({ values: allowed_values })
end

#format(bool) ⇒ Object



243
244
245
246
247
248
249
250
251
252
# File 'lib/hammer_cli/options/normalizers.rb', line 243

def format(bool)
  bool = bool.to_s
  if bool.downcase.match(/^(true|t|yes|y|1)$/i)
    return true
  elsif bool.downcase.match(/^(false|f|no|n|0)$/i)
    return false
  else
    raise ArgumentError, _('Value must be one of %s.') % ['true/false', 'yes/no', '1/0'].join(', ')
  end
end