Module: AMT::Utility

Defined in:
lib/amt/utility.rb,
lib/amt/utility/enum.rb,
lib/amt/utility/bit_struct.rb

Overview

This module houses utility classes that are used by the other AMT classes.

Defined Under Namespace

Classes: BitStruct, Enum

Class Method Summary collapse

Class Method Details

.binary_to_uuid(data) ⇒ Object

Create a UUID string from binary data which can either have a length of 16 characters (then it is considered to be a binary UUID) or a length of 32 characters (an already unpacked binary UUID).



15
16
17
18
19
20
# File 'lib/amt/utility.rb', line 15

def self.binary_to_uuid(data)
  data = data.unpack('H32').first if data.length == 16
  a = data.scan(/../)
  a[0,4].reverse.join('') + "-" + a[4,2].reverse.join('') + "-" + a[6,2].reverse.join('') +
    "-" + a[8,2].join('') + "-" + a[10,6].join('')
end

.uuid_to_binary(uuid) ⇒ Object

Convert a UUID string to binary data.



23
24
25
26
27
28
29
# File 'lib/amt/utility.rb', line 23

def self.uuid_to_binary(uuid)
  [uuid[0,8].scan(/../).reverse.join('') +
   uuid[9,4].scan(/../).reverse.join('') +
   uuid[14,4].scan(/../).reverse.join('') +
   uuid[19,4].scan(/../).join('') +
   uuid[24,12].scan(/../).join('')].pack('H32')
end