Class: Superstore::Types::IntegerType

Inherits:
BaseType
  • Object
show all
Defined in:
lib/superstore/types/integer_type.rb

Constant Summary collapse

REGEX =
/\A[-+]?\d+\Z/

Instance Attribute Summary

Attributes inherited from BaseType

#model, #options

Instance Method Summary collapse

Methods inherited from BaseType

#initialize

Constructor Details

This class inherits a constructor from Superstore::Types::BaseType

Instance Method Details

#decode(str) ⇒ Object



11
12
13
# File 'lib/superstore/types/integer_type.rb', line 11

def decode(str)
  str.to_i unless str.empty?
end

#encode(int) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
9
# File 'lib/superstore/types/integer_type.rb', line 5

def encode(int)
  raise ArgumentError.new("#{int.inspect} is not an Integer.") unless int.kind_of?(Integer)

  int
end

#typecast(value) ⇒ Object



15
16
17
# File 'lib/superstore/types/integer_type.rb', line 15

def typecast(value)
  value.to_i
end