ruby_xid 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruby_xid.rb +10 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52284a496e3475218d579654a6d484b307dceec8e6aae766ef954aa466681f43
|
4
|
+
data.tar.gz: 6f324b726dbf0bc3bcf8181586115df1aa32c35f405ef1da79f60991f87ca5bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f874017acb11d16aeb1edce7eb1786ff7baf5b2f43dd79369d0d9c91017d5d38fd6feb755ada4c763ecd20d7be8975f9e9ece4883000aa05b0f9c4d0549ec11
|
7
|
+
data.tar.gz: b2e8f5b3a8b895598e811a08112525bdd6b1f79e7eac439dd13c8e884fa891c4bc4bbe1c270c45e44a0b6b5e1bee494c2dc67f8be1a8fae0342e1b21dfbb9283
|
data/lib/ruby_xid.rb
CHANGED
@@ -7,10 +7,14 @@ class Xid
|
|
7
7
|
RAW_LEN = 12
|
8
8
|
TRIM_LEN = 20
|
9
9
|
|
10
|
+
attr_accessor :value
|
11
|
+
attr_reader :machine_id
|
12
|
+
|
10
13
|
def initialize(id = nil)
|
11
14
|
@mutex = Mutex.new
|
12
15
|
init_rand_int
|
13
16
|
@pid = Process.pid
|
17
|
+
@machine_id = real_machine_id
|
14
18
|
unless id.nil?
|
15
19
|
# Decoded array
|
16
20
|
@value = id
|
@@ -26,17 +30,17 @@ class Xid
|
|
26
30
|
|
27
31
|
def pid
|
28
32
|
# type: () -> int
|
29
|
-
(
|
33
|
+
(value[7] << 8 | value[8])
|
30
34
|
end
|
31
35
|
|
32
36
|
def counter
|
33
37
|
# type: () -> int
|
34
|
-
|
38
|
+
value[9] << 16 | value[10] << 8 | value[11]
|
35
39
|
end
|
36
40
|
|
37
41
|
def machine
|
38
42
|
# type: () -> str
|
39
|
-
|
43
|
+
value[4..6].map(&:chr).join('')
|
40
44
|
end
|
41
45
|
|
42
46
|
def datetime
|
@@ -45,11 +49,7 @@ class Xid
|
|
45
49
|
|
46
50
|
def time
|
47
51
|
# type: () -> int
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
def machine_id
|
52
|
-
@machine_id ||= real_machine_id
|
52
|
+
value[0] << 24 | value[1] << 16 | value[2] << 8 | value[3]
|
53
53
|
end
|
54
54
|
|
55
55
|
def string
|
@@ -60,7 +60,7 @@ class Xid
|
|
60
60
|
|
61
61
|
def bytes
|
62
62
|
# type: () -> str
|
63
|
-
|
63
|
+
value.map(&:chr).join('')
|
64
64
|
end
|
65
65
|
|
66
66
|
def init_rand_int
|
@@ -88,7 +88,7 @@ class Xid
|
|
88
88
|
|
89
89
|
def self.from_string(str)
|
90
90
|
val = Base32.b32decode(str)
|
91
|
-
value_check = val.select { |x| x >= 0 && x
|
91
|
+
value_check = val.select { |x| x >= 0 && x <= 255 }
|
92
92
|
|
93
93
|
(value_check.length..RAW_LEN - 1).each do |i|
|
94
94
|
value_check[i] = false
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_xid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Valarpiraichandran
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: a.valarpirai@gmail.com
|