Class: Lite::Uxid::Reversible::Hashid

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

Constant Summary collapse

MASK =
48

Instance Attribute Summary

Attributes inherited from Base

#id, #opts

Instance Method Summary collapse

Methods inherited from Base

decode, encode, #initialize

Constructor Details

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

Instance Method Details

#decodeObject



15
16
17
18
# File 'lib/lite/uxid/reversible/hashid.rb', line 15

def decode
  encoded_id = id.delete_prefix(coder_prefix.to_s)
  (decode_chars(encoded_id) >> MASK) - coder_salt
end

#encodeObject



10
11
12
13
# File 'lib/lite/uxid/reversible/hashid.rb', line 10

def encode
  encoded_id = encode_chars((id + coder_salt) << MASK)
  "#{coder_prefix}#{encoded_id}"
end