Class: Killbill::Litle::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/litle/litle_utils.rb

Constant Summary collapse

BASE62 =

Use base 62 to be safe on the Litle side

('0'..'9').to_a + ('A'..'Z').to_a + ('a'..'z').to_a

Class Method Summary collapse

Class Method Details

.compact_uuid(uuid) ⇒ Object



12
13
14
15
# File 'lib/litle/litle_utils.rb', line 12

def self.compact_uuid(uuid)
  uuid = uuid.gsub(/-/, '')
  uuid.hex.base(62).map{ |i| BASE62[i].chr } * ''
end

.unpack_uuid(base62_uuid) ⇒ Object



17
18
19
20
21
22
# File 'lib/litle/litle_utils.rb', line 17

def self.unpack_uuid(base62_uuid)
  as_hex = base62_uuid.split(//).inject(0) { |i,e| i*62 + BASE62.index(e[0]) }
  no_hyphens = "%x" % as_hex
  no_hyphens = '0' * (32 - no_hyphens.size) + no_hyphens
  no_hyphens.insert(8, "-").insert(13, "-").insert(18, "-").insert(23, "-")
end