Class: AWS::Record::Attributes::IntegerAttr

Inherits:
BaseAttr
  • Object
show all
Defined in:
lib/aws/record/attributes.rb

Direct Known Subclasses

Model::Attributes::IntegerAttr

Instance Attribute Summary

Attributes inherited from BaseAttr

#name, #options

Class Method Summary collapse

Methods inherited from BaseAttr

#default_value, deserialize, #deserialize, #initialize, #persist_as, #serialize, #set?, #type_cast

Constructor Details

This class inherits a constructor from AWS::Record::Attributes::BaseAttr

Class Method Details

.allow_set?Boolean

Returns:

  • (Boolean)


220
221
222
# File 'lib/aws/record/attributes.rb', line 220

def self.allow_set?
  true
end

.serialize(integer, options = {}) ⇒ String

Returns a serialized representation of the integer value suitable for storing in SimpleDB.

attribute.serialize(123)
#=> '123'

Parameters:

  • integer (Integer)

    The number to serialize.

  • options (Hash) (defaults to: {})

Returns:

  • (String)

    A serialized representation of the integer.



215
216
217
# File 'lib/aws/record/attributes.rb', line 215

def self.serialize integer, options = {}
  expect(Integer, integer) { integer }
end

.type_cast(raw_value, options = {}) ⇒ Integer?

Returns value cast to an integer. Empty strings are cast to nil by default. Type casting is done by calling #to_i on the value.

int_attribute.type_cast('123')
#=> 123

int_attribute.type_cast('')
#=> nil

Parameters:

  • raw_value (Mixed)

    The value to type cast to an integer.

Returns:

  • (Integer, nil)

    Returns the type casted integer or nil



194
195
196
197
198
199
200
201
202
203
204
# File 'lib/aws/record/attributes.rb', line 194

def self.type_cast raw_value, options = {}
  case raw_value
  when nil      then nil
  when ''       then nil
  when Integer  then raw_value
  else
    raw_value.respond_to?(:to_i) ? 
      raw_value.to_i :
      raw_value.to_s.to_i
  end
end