class HammerCLI::Options::Normalizers::Bool

Public Class Methods

common_description() click to toggle source
# File lib/hammer_cli/options/normalizers.rb, line 234
def common_description
  _('One of %s') % ['true/false', 'yes/no', '1/0'].join(', ')
end
completion_type() click to toggle source
# File lib/hammer_cli/options/normalizers.rb, line 230
def completion_type
  :boolean
end

Public Instance Methods

allowed_values() click to toggle source
# File lib/hammer_cli/options/normalizers.rb, line 239
def allowed_values
  ['yes', 'no', 'true', 'false', '1', '0']
end
complete(value) click to toggle source
# File lib/hammer_cli/options/normalizers.rb, line 254
def complete(value)
  allowed_values.map { |v| v + ' ' }
end
completion_type() click to toggle source
# File lib/hammer_cli/options/normalizers.rb, line 258
def completion_type
  super.merge({ values: allowed_values })
end
format(bool) click to toggle source
# 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