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

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

Instance Method Summary collapse

Instance Method Details

#complete(value) ⇒ Object



182
183
184
# File 'lib/hammer_cli/options/normalizers.rb', line 182

def complete(value)
  ["yes ", "no "]
end

#descriptionObject



167
168
169
# File 'lib/hammer_cli/options/normalizers.rb', line 167

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

#format(bool) ⇒ Object



171
172
173
174
175
176
177
178
179
180
# File 'lib/hammer_cli/options/normalizers.rb', line 171

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