Module: ID3Tag::NumberUtil

Defined in:
lib/id3tag/number_util.rb

Constant Summary collapse

FORMAT_FOR_8_BIT_SIGNED_INTEGER =
'c'
FORMAT_FOR_32BIT_INTEGER =
'N'

Class Method Summary collapse

Class Method Details

.convert_32bit_integer_to_string(integer) ⇒ Object



11
12
13
# File 'lib/id3tag/number_util.rb', line 11

def self.convert_32bit_integer_to_string(integer)
  [integer].pack(FORMAT_FOR_32BIT_INTEGER)
end

.convert_string_to_32bit_integer(string) ⇒ Object

Raises:

  • (ArgumentError)


5
6
7
8
9
# File 'lib/id3tag/number_util.rb', line 5

def self.convert_string_to_32bit_integer(string)
  raise(ArgumentError, "Input must be a string. #{string.inspect} given.") unless string.is_a?(::String)
  integers = string.unpack(FORMAT_FOR_32BIT_INTEGER)
  integers.first || raise(ArgumentError, "String: '#{string}' could not be decoded as 32-bit integer")
end