Class: Lite::Uxid::Ulid

Inherits:
Base
  • Object
show all
Defined in:
lib/lite/uxid/ulid.rb

Constant Summary collapse

MASK =
0x1f

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#encoding_base, #initialize

Constructor Details

This class inherits a constructor from Lite::Uxid::Base

Class Method Details

.encodeObject


13
14
15
16
# File 'lib/lite/uxid/ulid.rb', line 13

def encode
  klass = new
  klass.encode
end

Instance Method Details

#encodeObject


20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/lite/uxid/ulid.rb', line 20

def encode
  oct = octect
  ele = '0' * encoding_length
  pos = encoding_length - 1

  while oct.positive?
    ele[pos] = encoding_chars[oct & MASK]
    oct >>= 5
    pos -= 1
  end

  ele
end