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



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

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

.completion_typeObject



202
203
204
# File 'lib/hammer_cli/options/normalizers.rb', line 202

def completion_type
  :number
end

Instance Method Details

#format(val) ⇒ Object



211
212
213
214
215
216
217
# File 'lib/hammer_cli/options/normalizers.rb', line 211

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

#numeric?(val) ⇒ Boolean

Returns:

  • (Boolean)


219
220
221
# File 'lib/hammer_cli/options/normalizers.rb', line 219

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