lib/dmapparser/converter.rb in dmapparser-0.0.2 vs lib/dmapparser/converter.rb in dmapparser-0.1.0

- old
+ new

@@ -1,19 +1,19 @@ module DMAPParser # The DMAPConverter class converts between binary and ruby formats class Converter class << self def date_to_bin(data) - int_to_bin(value.to_i) + int_to_bin(data.to_i) end def bin_to_byte(data) data.unpack('C').first end def bin_to_long(data) - (bin_to_int(data[0..3]) << 32) + bin_to_int(data[4..7]) + (bin_to_int(data[0..3]) << 32) | bin_to_int(data[4..7]) end def bin_to_int(data) data.unpack('N').first end @@ -29,11 +29,11 @@ def bin_to_version(data) data.unpack('nCC').join '.' end def bin_to_hex(data) - data.bytes.reduce('') { |a, e| a + sprintf('%02X', e) } + data.bytes.reduce('') { |a, e| a + format('%02X', e) } end def bin_to_date(data) Time.at(bin_to_int(data)) end @@ -49,19 +49,19 @@ def byte_to_bin(data) [data.to_i].pack 'C' end def long_to_bin(data) - [data >> 32, data & 0xfffffff].pack 'NN' + [data >> 32, data & 0xFFFFFFFF].pack 'NN' end def short_to_bin(data) [data.to_i].pack 'n' end def version_to_bin(data) - data.split('.').pack 'nCC' + data.split('.').map { |part| part.to_i }.pack 'nCC' end def hex_to_bin(data) [data].pack 'H*' end @@ -106,21 +106,19 @@ def decode(type, data) decode_method = ('bin_to_' + type.to_s).to_sym if respond_to? decode_method send(decode_method, data) else - warn "Decoder: Unknown type #{type}" decode_unknown(data) end end def encode(type, data) encode_method = (type.to_s + '_to_bin').to_sym if respond_to? encode_method send(encode_method, data) else - warn "Encoder: Unknown type #{type}" - data + data # This only works for strings.. end end end end end