commonmeta-ruby 3.0.7 → 3.0.8
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/Gemfile.lock +1 -1
- data/lib/commonmeta/cli.rb +2 -2
- data/lib/commonmeta/utils.rb +2 -2
- data/lib/commonmeta/version.rb +1 -1
- data/spec/cli_spec.rb +14 -0
- data/spec/utils_spec.rb +3 -3
- 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: d158d95fcca721c5fd2052bd4175e5a39657794bc0b3478813c124b7627bbc4c
|
4
|
+
data.tar.gz: 89fae69b601b26e68e87f7714496c9b7dde50a77bbe11b7646756eefe1ffa13d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01e3aa82db4b968dc8b72670bec686c08e7f671c271173c32c53b1e027cc49b02e209da1826dcd24d2444d7b8bc434ce88f343568fde2dd467ec0dffadbe8cb7
|
7
|
+
data.tar.gz: 53ccb0ee19bb71c53eca55168185b77fe9535b55aa87634b239cf0b6bc83bef9692749d02c974c6101436a0089b99accd59d6d6181b56a5584e2eb993c7e225c
|
data/Gemfile.lock
CHANGED
data/lib/commonmeta/cli.rb
CHANGED
@@ -64,7 +64,7 @@ module Commonmeta
|
|
64
64
|
desc '', 'encode_id'
|
65
65
|
|
66
66
|
def encode_id
|
67
|
-
puts
|
67
|
+
puts encode_container_id
|
68
68
|
end
|
69
69
|
|
70
70
|
desc '', 'decode'
|
@@ -76,7 +76,7 @@ module Commonmeta
|
|
76
76
|
desc '', 'decode_id'
|
77
77
|
|
78
78
|
def decode_id(id)
|
79
|
-
puts
|
79
|
+
puts decode_container_id(id)
|
80
80
|
end
|
81
81
|
|
82
82
|
default_task :convert
|
data/lib/commonmeta/utils.rb
CHANGED
@@ -1351,14 +1351,14 @@ module Commonmeta
|
|
1351
1351
|
Base32::URL.decode(suffix)
|
1352
1352
|
end
|
1353
1353
|
|
1354
|
-
def
|
1354
|
+
def encode_container_id
|
1355
1355
|
# suffix has 5 digits plus two checksum digits. With base32 there are
|
1356
1356
|
# 32 possible digits, so 5 digits gives 32^5 possible combinations
|
1357
1357
|
random_int = SecureRandom.random_number(32 ** 4..(32 ** 5) - 1)
|
1358
1358
|
Base32::URL.encode(random_int, checksum: true)
|
1359
1359
|
end
|
1360
1360
|
|
1361
|
-
def
|
1361
|
+
def decode_container_id(id)
|
1362
1362
|
Base32::URL.decode(id)
|
1363
1363
|
end
|
1364
1364
|
end
|
data/lib/commonmeta/version.rb
CHANGED
data/spec/cli_spec.rb
CHANGED
@@ -306,4 +306,18 @@ describe Commonmeta::CLI do
|
|
306
306
|
expect { subject.decode input }.to output(/464528469187255429864\n/).to_stdout
|
307
307
|
end
|
308
308
|
end
|
309
|
+
|
310
|
+
describe "encode_id" do
|
311
|
+
it "random" do
|
312
|
+
expect { subject.encode_id }.to output(/[a-z0-9]+/).to_stdout
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
describe "decode_id" do
|
317
|
+
let(:input) { "h49ct36" }
|
318
|
+
|
319
|
+
it "blog post" do
|
320
|
+
expect { subject.decode_id input }.to output(/18397685862\n/).to_stdout
|
321
|
+
end
|
322
|
+
end
|
309
323
|
end
|
data/spec/utils_spec.rb
CHANGED
@@ -631,20 +631,20 @@ describe Commonmeta::Metadata, vcr: true do
|
|
631
631
|
|
632
632
|
context 'random id' do
|
633
633
|
it 'encode id' do
|
634
|
-
response = subject.
|
634
|
+
response = subject.encode_container_id
|
635
635
|
expect(response).to match(%r{[a-z0-9]+})
|
636
636
|
expect(response.length).to eq(7)
|
637
637
|
end
|
638
638
|
|
639
639
|
it 'decode id' do
|
640
640
|
id= '4425y27'
|
641
|
-
response = subject.
|
641
|
+
response = subject.decode_container_id(id)
|
642
642
|
expect(response).to eq(4_431_476_807)
|
643
643
|
end
|
644
644
|
|
645
645
|
it 'decode another id' do
|
646
646
|
id = 'gr1by89'
|
647
|
-
response = subject.
|
647
|
+
response = subject.decode_container_id(id)
|
648
648
|
expect(response).to eq(17_986_615_561)
|
649
649
|
end
|
650
650
|
end
|