Module: ShortUUID

Defined in:
lib/shortuuid.rb,
lib/shortuuid/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.expand(short_uuid, alphabet = Radix::BASE::B62) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/shortuuid.rb', line 9

def self.expand(short_uuid, alphabet = Radix::BASE::B62)
  uuid = short_uuid.b(alphabet).to_i.to_s(16).rjust(32, '0')
  [
    uuid[0..7],
    uuid[8..11],
    uuid[12..15],
    uuid[16..19],
    uuid[20..31]
  ].join('-')
end

.shorten(uuid, alphabet = Radix::BASE::B62) ⇒ Object



5
6
7
# File 'lib/shortuuid.rb', line 5

def self.shorten(uuid, alphabet = Radix::BASE::B62)
  uuid.split('-').join.to_i(16).b(10).to_s(alphabet)
end