active_uxid 1.0.11 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/active_uxid/hash.rb +7 -8
- data/lib/active_uxid/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d409ea9b9433696e7cb4854418fd0592c7e1c59
|
4
|
+
data.tar.gz: 38b9f9132f7cb8bc2d7725ad75b1c174ea2b2cc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cccf014569967ae286cbe07e83325693c40ddfc97a42d31c3bdcaf6102e48f01c615f2518c456a7949348e0bf734f882f4a0937fd1360fea8910a5052d09838
|
7
|
+
data.tar.gz: dd1304d11f680895f984014ec891176b3a61941b898997405dd43bd0e4762174c63eb06602614691336731b281672a0faef5ba993c487ff1766f3a1fbb9dc470
|
data/lib/active_uxid/hash.rb
CHANGED
@@ -3,10 +3,9 @@
|
|
3
3
|
module ActiveUxid
|
4
4
|
class Hash < ActiveUxid::Base
|
5
5
|
|
6
|
-
ENCODING_BASE ||= ENCODING_CHARS.length
|
7
|
-
|
8
6
|
def initialize(id)
|
9
7
|
@id = id
|
8
|
+
super()
|
10
9
|
end
|
11
10
|
|
12
11
|
def self.encode(id)
|
@@ -20,11 +19,11 @@ module ActiveUxid
|
|
20
19
|
end
|
21
20
|
|
22
21
|
def encode_uxid
|
23
|
-
uxid_encode_chars((@id +
|
22
|
+
uxid_encode_chars((@id + encoding_salt) << encoding_length)
|
24
23
|
end
|
25
24
|
|
26
25
|
def decode_uxid
|
27
|
-
(uxid_decode_chars(@id) >>
|
26
|
+
(uxid_decode_chars(@id) >> encoding_length) - encoding_salt
|
28
27
|
end
|
29
28
|
|
30
29
|
def uxid_encode_chars(id)
|
@@ -34,8 +33,8 @@ module ActiveUxid
|
|
34
33
|
str = ''
|
35
34
|
|
36
35
|
while id.positive?
|
37
|
-
str = "#{
|
38
|
-
id /=
|
36
|
+
str = "#{encoding_chars[id % encoding_base]}#{str}"
|
37
|
+
id /= encoding_base
|
39
38
|
end
|
40
39
|
|
41
40
|
str
|
@@ -48,8 +47,8 @@ module ActiveUxid
|
|
48
47
|
max = len - 1
|
49
48
|
|
50
49
|
while pos < len
|
51
|
-
pow =
|
52
|
-
num +=
|
50
|
+
pow = encoding_base ** (max - pos)
|
51
|
+
num += encoding_chars.index(id[pos]) * pow
|
53
52
|
pos += 1
|
54
53
|
end
|
55
54
|
|
data/lib/active_uxid/version.rb
CHANGED