ruby-ulid 0.6.0 → 0.6.1
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/README.md +7 -7
- data/lib/ulid/crockford_base32.rb +13 -9
- data/lib/ulid/version.rb +1 -1
- data/sig/ulid.rbs +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c7cf89034d0f74026278e2a4c113d57f8fc28b861b8bcf1d2210dbb76688e52
|
4
|
+
data.tar.gz: 340bfbea8fb1ff3ec0e49339e2a5a388a81552f8cd73a65ad9ff049448fc0c3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74d26cb5dc49a8d79a5c933817c1c8913954d675d996a91057f29859fd1fdf0a32c99d8121ef954e1d7d400110fa1737be17a9084bfc03655082de96c9614392
|
7
|
+
data.tar.gz: 96f19838c4c90ee313722857f88693e88f247e5380293291b362eadc834f6adb1613c01034a0cfe430f24576b4fea55f252b79f689b00c3e05b739118db8906e
|
data/README.md
CHANGED
@@ -49,7 +49,7 @@ Should be installed!
|
|
49
49
|
Add this line in your Gemfile.
|
50
50
|
|
51
51
|
```ruby
|
52
|
-
gem('ruby-ulid', '~> 0.6.
|
52
|
+
gem('ruby-ulid', '~> 0.6.1')
|
53
53
|
```
|
54
54
|
|
55
55
|
### How to use
|
@@ -58,10 +58,10 @@ gem('ruby-ulid', '~> 0.6.0')
|
|
58
58
|
require 'ulid'
|
59
59
|
|
60
60
|
ULID::VERSION
|
61
|
-
# => "0.6.
|
61
|
+
# => "0.6.1"
|
62
62
|
```
|
63
63
|
|
64
|
-
NOTE: This README includes info about development version. If you would see released version's one. [Look at the ref](https://github.com/kachick/ruby-ulid/tree/v0.6.
|
64
|
+
NOTE: This README includes info about development version. If you would see released version's one. [Look at the ref](https://github.com/kachick/ruby-ulid/tree/v0.6.1).
|
65
65
|
|
66
66
|
### Generator and Parser
|
67
67
|
|
@@ -118,11 +118,11 @@ ULID.decode_time('00VHNCZB00SYG7RCEXZC9DA4E1', in: '+09:00') #=> 2000-01-01 09:0
|
|
118
118
|
|
119
119
|
This project does not prioritize the speed. However it actually works faster than others! :zap:
|
120
120
|
|
121
|
-
Snapshot on 0.6.
|
121
|
+
Snapshot on 0.6.1 is below
|
122
122
|
|
123
|
-
* Generator is 1.
|
124
|
-
* Generator is 1.
|
125
|
-
* Parser is 2.
|
123
|
+
* Generator is 1.5x faster than - [ulid gem](https://github.com/rafaelsales/ulid)
|
124
|
+
* Generator is 1.9x faster than - [ulid-ruby gem](https://github.com/abachman/ulid-ruby)
|
125
|
+
* Parser is 2.7x faster than - [ulid-ruby gem](https://github.com/abachman/ulid-ruby)
|
126
126
|
|
127
127
|
You can see further detail at [Benchmark](https://github.com/kachick/ruby-ulid/wiki/Benchmark).
|
128
128
|
|
@@ -15,8 +15,7 @@ class ULID
|
|
15
15
|
# * https://github.com/kachick/ruby-ulid/issues/57
|
16
16
|
# * https://github.com/kachick/ruby-ulid/issues/78
|
17
17
|
module CrockfordBase32
|
18
|
-
|
19
|
-
base32_to_crockford = {
|
18
|
+
same_definitions = {
|
20
19
|
'0' => '0',
|
21
20
|
'1' => '1',
|
22
21
|
'2' => '2',
|
@@ -34,7 +33,11 @@ class ULID
|
|
34
33
|
'E' => 'E',
|
35
34
|
'F' => 'F',
|
36
35
|
'G' => 'G',
|
37
|
-
'H' => 'H'
|
36
|
+
'H' => 'H'
|
37
|
+
}.freeze
|
38
|
+
|
39
|
+
# Excluded I, L, O, U, - from Base32
|
40
|
+
base32_to_crockford = {
|
38
41
|
'I' => 'J',
|
39
42
|
'J' => 'K',
|
40
43
|
'K' => 'M',
|
@@ -51,9 +54,10 @@ class ULID
|
|
51
54
|
'V' => 'Z'
|
52
55
|
}.freeze
|
53
56
|
BASE32_TR_PATTERN = base32_to_crockford.keys.join.freeze
|
54
|
-
|
57
|
+
CROCKFORD_TR_PATTERN = base32_to_crockford.values.join.freeze
|
58
|
+
ENCODING_STRING = "#{same_definitions.values.join}#{CROCKFORD_TR_PATTERN}".freeze
|
55
59
|
|
56
|
-
|
60
|
+
variant_to_normarized = {
|
57
61
|
'L' => '1',
|
58
62
|
'l' => '1',
|
59
63
|
'I' => '1',
|
@@ -61,8 +65,8 @@ class ULID
|
|
61
65
|
'O' => '0',
|
62
66
|
'o' => '0'
|
63
67
|
}.freeze
|
64
|
-
VARIANT_TR_PATTERN =
|
65
|
-
NORMALIZED_TR_PATTERN =
|
68
|
+
VARIANT_TR_PATTERN = variant_to_normarized.keys.join.freeze
|
69
|
+
NORMALIZED_TR_PATTERN = variant_to_normarized.values.join.freeze
|
66
70
|
|
67
71
|
# @note Avoid to depend regex as possible. `tr(string, string)` is almost 2x Faster than `gsub(regex, hash)` in Ruby 3.1
|
68
72
|
|
@@ -70,7 +74,7 @@ class ULID
|
|
70
74
|
# @param [String] string
|
71
75
|
# @return [Integer]
|
72
76
|
def self.decode(string)
|
73
|
-
n32encoded = string.upcase.tr(
|
77
|
+
n32encoded = string.upcase.tr(CROCKFORD_TR_PATTERN, BASE32_TR_PATTERN)
|
74
78
|
n32encoded.to_i(32)
|
75
79
|
end
|
76
80
|
|
@@ -93,7 +97,7 @@ class ULID
|
|
93
97
|
# @param [String] n32encoded
|
94
98
|
# @return [String]
|
95
99
|
def self.from_n32(n32encoded)
|
96
|
-
n32encoded.upcase.tr(BASE32_TR_PATTERN,
|
100
|
+
n32encoded.upcase.tr(BASE32_TR_PATTERN, CROCKFORD_TR_PATTERN)
|
97
101
|
end
|
98
102
|
end
|
99
103
|
end
|
data/lib/ulid/version.rb
CHANGED
data/sig/ulid.rbs
CHANGED