Class: DataTypes::Float64

Inherits:
BaseType show all
Defined in:
lib/active_model_serializers_binary/data_types.rb

Instance Attribute Summary

Attributes inherited from BaseType

#bit_length, #count, #endianess, #length, #name, #parent, #raw_value, #sign, #type, #value

Instance Method Summary collapse

Methods inherited from BaseType

#after_load, #before_dump, #check, #check_raw_value, #check_value, #size, #to_s, #trim

Constructor Details

#initialize(options = {}) ⇒ Float64

Returns a new instance of Float64.



229
230
231
# File 'lib/active_model_serializers_binary/data_types.rb', line 229

def initialize(options = {})
  super options.merge :bit_length => 64, :sign => nil, :default_value => 0.0
end

Instance Method Details

#dump(value = nil) ⇒ Object



233
234
235
236
237
238
239
240
# File 'lib/active_model_serializers_binary/data_types.rb', line 233

def dump(value=nil)
  before_dump( value )
  if @endianess == :big
    @raw_value = @value.pack('G*').unpack('C*')
  else
    @raw_value = @value.pack('E*').unpack('C*')
  end
end

#load(raw_value) ⇒ Object



242
243
244
245
246
247
248
249
# File 'lib/active_model_serializers_binary/data_types.rb', line 242

def load(raw_value)
  if @endianess == :big
    self.value = check_raw_value(raw_value).pack('C*').unpack('G*') if !value.nil?
  else
    self.value = check_raw_value(raw_value).pack('C*').unpack('E*') if !value.nil?
  end
  after_load
end