Module: Packable::Extensions::Float::ClassMethods

Defined in:
lib/packable/extensions/float.rb

Overview

:nodoc:

Constant Summary collapse

ENDIAN_TO_FORMAT =
Hash.new{|h, endian| raise ArgumentError, "Endian #{endian} is not valid. It must be one of #{h.keys.join(', ')}"}.
merge!(:big => "G", :network => "G", :little => "E", :native => "F").freeze

Instance Method Summary collapse

Instance Method Details

#pack_option_to_format(options) ⇒ Object



25
26
27
28
29
# File 'lib/packable/extensions/float.rb', line 25

def pack_option_to_format(options)
  format = ENDIAN_TO_FORMAT[options[:endian]]
  format.downcase! if options[:precision] == :single
  format
end

#read_packed(io, options) ⇒ Object



31
32
33
34
35
# File 'lib/packable/extensions/float.rb', line 31

def read_packed(io, options)
  io.read({:single => 4, :double => 8}[options[:precision]])   \
    .unpack(pack_option_to_format(options))   \
    .first
end