Class: Lite::Uxid::Irreversible::Ulid

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

Constant Summary collapse

MASK =
0x1f

Instance Attribute Summary

Attributes inherited from Base

#opts

Instance Method Summary collapse

Methods inherited from Base

decode, #decode, encode, #initialize

Methods included from Base

#decode

Constructor Details

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

Instance Method Details

#encodeObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/lite/uxid/irreversible/ulid.rb', line 10

def encode
  encoded_id = "0" * coder_size
  oct = octect
  pos = coder_size - 1

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

  "#{coder_prefix}#{encoded_id}"
end