Class: AWS::Record::Model::Attributes::SortableIntegerAttr
- Inherits:
-
IntegerAttr
- Object
- Attributes::BaseAttr
- Attributes::IntegerAttr
- IntegerAttr
- AWS::Record::Model::Attributes::SortableIntegerAttr
- Defined in:
- lib/aws/record/model/attributes.rb
Instance Attribute Summary
Attributes inherited from Attributes::BaseAttr
Class Method Summary collapse
- .deserialize(string_value, options = {}) ⇒ Object
-
.serialize(integer, options = {}) ⇒ String
Returns a serialized representation of the integer value suitable for storing in SimpleDB.
Instance Method Summary collapse
-
#initialize(name, options = {}) ⇒ SortableIntegerAttr
constructor
A new instance of SortableIntegerAttr.
Methods inherited from Attributes::IntegerAttr
Methods inherited from Attributes::BaseAttr
allow_set?, #default_value, #deserialize, #persist_as, #serialize, #set?, #type_cast
Constructor Details
#initialize(name, options = {}) ⇒ SortableIntegerAttr
Returns a new instance of SortableIntegerAttr.
42 43 44 45 46 47 48 |
# File 'lib/aws/record/model/attributes.rb', line 42 def initialize name, = {} range = [:range] raise ArgumentError, "missing required option :range" unless range raise ArgumentError, ":range should be a integer range" unless range.is_a?(Range) and range.first.is_a?(Integer) super(name, ) end |
Class Method Details
.deserialize(string_value, options = {}) ⇒ Object
80 81 82 83 84 |
# File 'lib/aws/record/model/attributes.rb', line 80 def self.deserialize string_value, = {} offset_and_precision() do |offset,precision| string_value.to_i - offset end end |
.serialize(integer, options = {}) ⇒ String
Returns a serialized representation of the integer value suitable for storing in SimpleDB.
attribute.serialize(123)
#=> '123'
# padded to the correct number of digits
attribute.serialize('123', :range => (0..10_000)
#=> '00123'
# offset applied to make all values positive
attribute.serialize('-55', :range => (-100..10_000)
#=> '00045'
71 72 73 74 75 76 77 78 |
# File 'lib/aws/record/model/attributes.rb', line 71 def self.serialize integer, = {} expect(Integer, integer) do check_range(integer, ) offset_and_precision() do |offset,precision| "%0#{precision}d" % (integer.to_i + offset) end end end |