Class: Lite::Uxid::Reversible::Hashid
- Inherits:
-
Base
- Object
- Base
- Lite::Uxid::Reversible::Hashid
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
Instance Method Details
#decode ⇒ Object
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
|
#encode ⇒ Object
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
|