shortuuid 0.2.0 → 0.4.0
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 +2 -2
- data/lib/shortuuid.rb +30 -5
- data/lib/shortuuid/version.rb +1 -1
- data/shortuuid.gemspec +0 -1
- metadata +3 -19
- data/.travis.yml +0 -4
- data/circle.yml +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e301bebd9f1f14532b00b2c8103451a423d1d7d
|
4
|
+
data.tar.gz: ff2c4df14dce722dc3bb3b05b2c97f1cb668c4ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d37976f65434d780ce680d84fc8ccd025370591a2e39a09b48678640b07c079a7383ca102f020fa95659de801520cee151a7937b0217aa6e858dbd7db757a5a
|
7
|
+
data.tar.gz: 79a5c5fcc2a2d6dc712ea144521b70dccfa2fc5aa18f9dcc24882dc04175d408029d3a0a9b7ba1bffd7bfae1113608bd8b19605c30e580d54215e4301adc1fdc
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# ShortUUID [](https://circleci.com/gh/sudhirj/shortuuid)
|
2
2
|
|
3
3
|
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/shortuuid`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
4
|
|
@@ -22,7 +22,7 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
|
26
26
|
|
27
27
|
## Development
|
28
28
|
|
data/lib/shortuuid.rb
CHANGED
@@ -1,15 +1,40 @@
|
|
1
1
|
require 'shortuuid/version'
|
2
|
-
require 'radix'
|
3
2
|
|
4
3
|
module ShortUUID
|
5
|
-
|
4
|
+
DEFAULT_BASE62 = %w(0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z).freeze
|
5
|
+
|
6
|
+
def self.shorten(uuid, alphabet = DEFAULT_BASE62)
|
6
7
|
return nil unless uuid && !uuid.empty?
|
7
|
-
uuid.split('-').join.to_i(16)
|
8
|
+
decimal_value = uuid.split('-').join.to_i(16)
|
9
|
+
convert_decimal_to_alphabet(decimal_value, alphabet)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.convert_decimal_to_alphabet(decimal, alphabet)
|
13
|
+
alphabet = alphabet.to_a
|
14
|
+
radix = alphabet.length
|
15
|
+
i = decimal.to_i
|
16
|
+
out = []
|
17
|
+
loop do
|
18
|
+
break if i == 0
|
19
|
+
out.unshift(alphabet[i % radix])
|
20
|
+
i /= radix
|
21
|
+
end
|
22
|
+
out.join
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.convert_alphabet_to_decimal(word, alphabet)
|
26
|
+
num = 0
|
27
|
+
radix = alphabet.length
|
28
|
+
word.chars.reverse.each_with_index do |char, index|
|
29
|
+
num += alphabet.index(char) * (radix**index)
|
30
|
+
end
|
31
|
+
num
|
8
32
|
end
|
9
33
|
|
10
|
-
def self.expand(short_uuid, alphabet =
|
34
|
+
def self.expand(short_uuid, alphabet = DEFAULT_BASE62)
|
11
35
|
return nil unless short_uuid && !short_uuid.empty?
|
12
|
-
|
36
|
+
decimal_value = convert_alphabet_to_decimal(short_uuid, alphabet)
|
37
|
+
uuid = decimal_value.to_s(16).rjust(32, '0')
|
13
38
|
[
|
14
39
|
uuid[0..7],
|
15
40
|
uuid[8..11],
|
data/lib/shortuuid/version.rb
CHANGED
data/shortuuid.gemspec
CHANGED
@@ -18,7 +18,6 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency 'radix'
|
22
21
|
spec.add_development_dependency 'bundler', '~> 1.11'
|
23
22
|
spec.add_development_dependency 'rake', '~> 10.0'
|
24
23
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shortuuid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sudhir Jonathan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: radix
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: bundler
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,7 +60,6 @@ extensions: []
|
|
74
60
|
extra_rdoc_files: []
|
75
61
|
files:
|
76
62
|
- ".gitignore"
|
77
|
-
- ".travis.yml"
|
78
63
|
- CODE_OF_CONDUCT.md
|
79
64
|
- Gemfile
|
80
65
|
- LICENSE.txt
|
@@ -82,7 +67,6 @@ files:
|
|
82
67
|
- Rakefile
|
83
68
|
- bin/console
|
84
69
|
- bin/setup
|
85
|
-
- circle.yml
|
86
70
|
- lib/shortuuid.rb
|
87
71
|
- lib/shortuuid/version.rb
|
88
72
|
- shortuuid.gemspec
|
@@ -106,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
90
|
version: '0'
|
107
91
|
requirements: []
|
108
92
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.5.
|
93
|
+
rubygems_version: 2.5.1
|
110
94
|
signing_key:
|
111
95
|
specification_version: 4
|
112
96
|
summary: Quickly and easily convert UUIDs to space efficient Base58 strings.
|
data/.travis.yml
DELETED
data/circle.yml
DELETED