Class: Caty::IntegerConverter

Inherits:
Converter show all
Defined in:
lib/caty/converters.rb

Overview

Converter for integer values:

/^[+-]?[0-9]+$/

Instance Method Summary collapse

Methods inherited from Converter

type, types

Instance Method Details

#convert(value) ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'lib/caty/converters.rb', line 90

def convert( value )
    case value
    when %r{^[+-]?[0-9]+$} then value.to_i
    else
        e = Caty::OptionArgumentError.new
        e.expected = 'an integer'
        raise e
    end
end