Class: HammerCLI::Options::Normalizers::Number

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractNormalizer

#complete, #completion_type, #description, inherited

Class Method Details

.common_descriptionObject



209
210
211
# File 'lib/hammer_cli/options/normalizers.rb', line 209

def common_description
  _('Numeric value. Integer')
end

.completion_typeObject



205
206
207
# File 'lib/hammer_cli/options/normalizers.rb', line 205

def completion_type
  :number
end

Instance Method Details

#format(val) ⇒ Object



214
215
216
217
218
219
220
# File 'lib/hammer_cli/options/normalizers.rb', line 214

def format(val)
  if numeric?(val)
    val.to_i
  else
    raise ArgumentError, _("Numeric value is required.")
  end
end

#numeric?(val) ⇒ Boolean

Returns:

  • (Boolean)


222
223
224
# File 'lib/hammer_cli/options/normalizers.rb', line 222

def numeric?(val)
  Integer(val) != nil rescue false
end