Module: SimpleMapper::Attributes::Types::Integer

Defined in:
lib/simple_mapper/attributes/types.rb

Class Method Summary collapse

Class Method Details

.convert(value) ⇒ Object



171
172
173
174
175
176
177
# File 'lib/simple_mapper/attributes/types.rb', line 171

def self.convert(value)
  converted = value.to_i
  unless value == converted or value.to_s == converted.to_s or converted.to_f.to_s == value.to_s
    raise SimpleMapper::TypeConversionException, "cannot convert #{value} to Integer"
  end
  converted
end

.decode(value) ⇒ Object



185
186
187
# File 'lib/simple_mapper/attributes/types.rb', line 185

def self.decode(value)
  convert(value)
end

.encode(value) ⇒ Object

raise a TypeConversionException if not a valid Integer otherwise, convert to a string



181
182
183
# File 'lib/simple_mapper/attributes/types.rb', line 181

def self.encode(value)
  convert(value).to_s
end