ruby-short_url 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/README.md +6 -0
- data/Rakefile +8 -0
- data/bin/console +1 -1
- data/lib/ruby/short_url/encoder.rb +12 -18
- data/lib/ruby/short_url/version.rb +1 -1
- data/lib/{ruby/short_url.rb → ruby-short_url.rb} +0 -5
- data/ruby-short_url.gemspec +6 -2
- metadata +67 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8ab1032da6a39eb445cfce821c89e2c7c461693
|
4
|
+
data.tar.gz: 829d03e252835c6df58ffa0965a853b3b9cc3cc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fa0fdcbf10d2571ff2bae985189380a770ece3dbe06ae22aab7ee378f0a1accb6f89a2ebe085e9821f68091e9ccc92b2a293c3922dc18295935014bf1839f53
|
7
|
+
data.tar.gz: 64972d39fba9be3d4aca0baedcb942472357d9ece885689d3e84208a3c9155c32d248b840b13ed765f9d435d7e3db90f99cf04c4807f2b672dc9e290220f9e0d
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Ruby::ShortUrl
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/toshimaru/ruby-short_url.svg?branch=master)](https://travis-ci.org/toshimaru/ruby-short_url)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/ruby-short_url.svg)](http://badge.fury.io/rb/ruby-short_url)
|
5
|
+
[![Dependency Status](https://gemnasium.com/toshimaru/ruby-short_url.svg)](https://gemnasium.com/toshimaru/ruby-short_url)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/toshimaru/ruby-short_url/badges/coverage.svg)](https://codeclimate.com/github/toshimaru/ruby-short_url/coverage)
|
7
|
+
[![Code Climate](https://codeclimate.com/github/toshimaru/ruby-short_url/badges/gpa.svg)](https://codeclimate.com/github/toshimaru/ruby-short_url)
|
8
|
+
|
3
9
|
Ruby implementation for generating Tiny URL. Ruby implementation of [python-short_url](https://github.com/Alir3z4/python-short_url)
|
4
10
|
|
5
11
|
> A bit-shuffling approach is used to avoid generating consecutive, predictable URLs. However, the algorithm is deterministic and will guarantee that no collisions will occur.
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -7,6 +7,7 @@ module Ruby
|
|
7
7
|
MIN_LENGTH = 5
|
8
8
|
|
9
9
|
def initialize(alphabet: DEFAULT_ALPHABET, block_size: DEFAULT_BLOCK_SIZE)
|
10
|
+
raise ArgumentError.new 'Alphabet has to contain at least 2 characters.' if alphabet.length < 2
|
10
11
|
@alphabet = alphabet
|
11
12
|
@block_size = block_size
|
12
13
|
@mask = (1 << block_size) - 1
|
@@ -31,7 +32,7 @@ module Ruby
|
|
31
32
|
(n & ~@mask) | _decode(n & @mask)
|
32
33
|
end
|
33
34
|
|
34
|
-
def enbase(x, min_length
|
35
|
+
def enbase(x, min_length)
|
35
36
|
result = _enbase(x)
|
36
37
|
padding_length = min_length - result.length
|
37
38
|
padding_length = 0 if padding_length < 0
|
@@ -41,32 +42,25 @@ module Ruby
|
|
41
42
|
|
42
43
|
def debase(x)
|
43
44
|
n = @alphabet.length
|
44
|
-
result
|
45
|
-
|
46
|
-
unless @alphabet.index(c).nil?
|
47
|
-
result += @alphabet.index(c) * (n ** i)
|
48
|
-
end
|
45
|
+
x.split('').reverse.each_with_index.inject(0) do |result, (c, i)|
|
46
|
+
result += @alphabet.index(c) * (n ** i)
|
49
47
|
end
|
50
|
-
result
|
51
48
|
end
|
52
49
|
|
53
50
|
def _encode(n)
|
54
|
-
result
|
55
|
-
|
56
|
-
if (n & (1 << i)) != 0
|
57
|
-
result |= (1 << b)
|
58
|
-
end
|
51
|
+
@mapping.reverse.each_with_index.inject(0) do |result, (b, i)|
|
52
|
+
_calc_result(result, n, b, i)
|
59
53
|
end
|
60
|
-
result
|
61
54
|
end
|
62
55
|
|
63
56
|
def _decode(n)
|
64
|
-
result
|
65
|
-
|
66
|
-
if n & (1 << b) != 0
|
67
|
-
result |= (1 << i)
|
68
|
-
end
|
57
|
+
@mapping.reverse.each_with_index.inject(0) do |result, (b, i)|
|
58
|
+
_calc_result(result, n, i, b)
|
69
59
|
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def _calc_result(result, n, x, y)
|
63
|
+
return result |= (1 << x) if n & (1 << y) != 0
|
70
64
|
result
|
71
65
|
end
|
72
66
|
|
data/ruby-short_url.gemspec
CHANGED
@@ -16,6 +16,10 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
|
-
spec.add_development_dependency "bundler"
|
20
|
-
spec.add_development_dependency "
|
19
|
+
spec.add_development_dependency "bundler"
|
20
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
21
|
+
spec.add_development_dependency "minitest"
|
22
|
+
spec.add_development_dependency "minitest-reporters"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "simplecov"
|
21
25
|
end
|
metadata
CHANGED
@@ -1,43 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-short_url
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- toshi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: codeclimate-test-reporter
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest-reporters
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
27
69
|
- !ruby/object:Gem::Dependency
|
28
70
|
name: rake
|
29
71
|
requirement: !ruby/object:Gem::Requirement
|
30
72
|
requirements:
|
31
|
-
- - "
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
32
88
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
89
|
+
version: '0'
|
34
90
|
type: :development
|
35
91
|
prerelease: false
|
36
92
|
version_requirements: !ruby/object:Gem::Requirement
|
37
93
|
requirements:
|
38
|
-
- - "
|
94
|
+
- - ">="
|
39
95
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
96
|
+
version: '0'
|
41
97
|
description:
|
42
98
|
email:
|
43
99
|
- me@toshimaru.net
|
@@ -53,7 +109,7 @@ files:
|
|
53
109
|
- Rakefile
|
54
110
|
- bin/console
|
55
111
|
- bin/setup
|
56
|
-
- lib/ruby
|
112
|
+
- lib/ruby-short_url.rb
|
57
113
|
- lib/ruby/short_url/encoder.rb
|
58
114
|
- lib/ruby/short_url/version.rb
|
59
115
|
- ruby-short_url.gemspec
|