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



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

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

.completion_typeObject



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

def completion_type
  :boolean
end

Instance Method Details

#allowed_valuesObject



236
237
238
# File 'lib/hammer_cli/options/normalizers.rb', line 236

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

#complete(value) ⇒ Object



251
252
253
# File 'lib/hammer_cli/options/normalizers.rb', line 251

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

#completion_typeObject



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

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

#format(bool) ⇒ Object



240
241
242
243
244
245
246
247
248
249
# File 'lib/hammer_cli/options/normalizers.rb', line 240

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