Class: AWS::Record::Attributes::IntegerAttr
- Defined in:
- lib/aws/record/attributes.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from BaseAttr
Class Method Summary collapse
- .allow_set? ⇒ Boolean
-
.serialize(integer, options = {}) ⇒ String
Returns a serialized representation of the integer value suitable for storing in SimpleDB.
-
.type_cast(raw_value, options = {}) ⇒ Integer?
Returns value cast to an integer.
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
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'
215 216 217 |
# File 'lib/aws/record/attributes.rb', line 215 def self.serialize integer, = {} 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
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, = {} 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 |