Class: AWS::Record::Model::Attributes::SortableFloatAttr

Inherits:
FloatAttr show all
Defined in:
lib/aws/record/model/attributes.rb

Instance Attribute Summary

Attributes inherited from Attributes::BaseAttr

#name, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Attributes::FloatAttr

allow_set?, type_cast

Methods inherited from Attributes::BaseAttr

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

Constructor Details

#initialize(name, options = {}) ⇒ SortableFloatAttr

Returns a new instance of SortableFloatAttr.

Raises:

  • (ArgumentError)


111
112
113
114
115
116
117
# File 'lib/aws/record/model/attributes.rb', line 111

def initialize name, options = {}
  range = options[:range]
  raise ArgumentError, "missing required option :range" unless range
  raise ArgumentError, ":range should be an integer range" unless
    range.is_a?(Range) and range.first.is_a?(Integer)
  super(name, options)
end

Class Method Details

.deserialize(string_value, options = {}) ⇒ Object



128
129
130
131
132
133
134
# File 'lib/aws/record/model/attributes.rb', line 128

def self.deserialize string_value, options = {}
  expect(String, string_value) do
    left, right = string_value.split('.')
    left = SortableIntegerAttr.deserialize(left, options)
    "#{left}.#{right}".to_f
  end
end

.serialize(float, options = {}) ⇒ Object



119
120
121
122
123
124
125
126
# File 'lib/aws/record/model/attributes.rb', line 119

def self.serialize float, options = {}
  expect(Float, float) do 
    left, right = float.to_s.split('.')
    left = SortableIntegerAttr.serialize(left.to_i, options)
    SortableIntegerAttr.check_range(float, options)
    "#{left}.#{right}"
  end
end