Class: Ronin::Core::Params::Types::Integer
- Defined in:
- lib/ronin/core/params/types/integer.rb
Overview
Represents a numeric value.
Instance Attribute Summary
Attributes inherited from Numeric
Instance Method Summary collapse
-
#coerce(value) ⇒ ::Integer
private
Coerces a String into an Integer value.
Methods inherited from Numeric
Constructor Details
This class inherits a constructor from Ronin::Core::Params::Types::Numeric
Instance Method Details
#coerce(value) ⇒ ::Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Coerces a String into an Integer value.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ronin/core/params/types/integer.rb', line 45 def coerce(value) case value when ::Integer then super(value) when ::String case value when /\A[+-]?\d+\z/ super(value.to_i) when /\A[+-]?0b[01]+\z/ super(parse_binary(value)) when /\A[+-]?(?:0x)?[0-9A-Fa-f]+\z/ super(parse_hexadecimal(value)) else raise(ValidationError,"value contains non-numeric characters (#{value.inspect})") end else if value.respond_to?(:to_i) super(value.to_i) else raise(ValidationError,"value does not define a #to_i method (#{value.inspect})") end end end |