Class: OptParseValidator::OptInteger

Inherits:
OptBase
  • Object
show all
Defined in:
lib/opt_parse_validator/opts/integer.rb

Overview

Implementation of the Integer Option

Direct Known Subclasses

OptPositiveInteger

Instance Attribute Summary

Attributes inherited from OptBase

#attrs, #option, #required

Instance Method Summary collapse

Methods inherited from OptBase

#choices, #default, #initialize, #normalize, #required?, #required_unless, #to_long, #to_s, #to_sym, #value_if_empty

Constructor Details

This class inherits a constructor from OptParseValidator::OptBase

Instance Method Details

#validate(value) ⇒ Integer

Parameters:

  • value (String)

Returns:

  • (Integer)


7
8
9
10
# File 'lib/opt_parse_validator/opts/integer.rb', line 7

def validate(value)
  fail "#{value} is not an integer" if value.to_i.to_s != value
  value.to_i
end