ruby-short_url 0.2.0 → 0.3.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 +6 -3
- data/README.md +29 -3
- data/lib/ruby/short_url/encoder.rb +4 -2
- data/lib/ruby/short_url/version.rb +1 -1
- data/ruby-short_url.gemspec +3 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5469b8213eece32a1f885ebe7b3f079358fdfc06
|
4
|
+
data.tar.gz: 7a2b5f97806297fc6165f470a245a1ac9122f680
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45ef206a770e52b5554529b721fdb654388e17258fd89594dbbf65128672470a23dd83a99bbd927bc89836d9f4cc30496a20f3a8d2761755b10eaa36c77f2db1
|
7
|
+
data.tar.gz: 61a42c4e7b44dddaaf07f8d7132296d6c3091a7efc90112a6eba3c87f89f8d3c189d663f3d2e143d22cae04c944ac10141b53fdf3e6af9272d1db5a696fc113a
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/toshimaru/ruby-short_url.svg?branch=master)](https://travis-ci.org/toshimaru/ruby-short_url)
|
4
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
5
|
[![Test Coverage](https://codeclimate.com/github/toshimaru/ruby-short_url/badges/coverage.svg)](https://codeclimate.com/github/toshimaru/ruby-short_url/coverage)
|
7
6
|
[![Code Climate](https://codeclimate.com/github/toshimaru/ruby-short_url/badges/gpa.svg)](https://codeclimate.com/github/toshimaru/ruby-short_url)
|
7
|
+
[![Dependency Status](https://gemnasium.com/toshimaru/ruby-short_url.svg)](https://gemnasium.com/toshimaru/ruby-short_url)
|
8
8
|
|
9
9
|
Ruby implementation for generating Tiny URL. Ruby implementation of [python-short_url](https://github.com/Alir3z4/python-short_url)
|
10
10
|
|
@@ -14,7 +14,7 @@ More detail is [here](https://github.com/Alir3z4/python-short_url#short-url-gene
|
|
14
14
|
|
15
15
|
## Installation
|
16
16
|
|
17
|
-
Add this line to your application's Gemfile
|
17
|
+
Add this line to your application's `Gemfile`:
|
18
18
|
|
19
19
|
```ruby
|
20
20
|
gem 'ruby-short_url'
|
@@ -38,7 +38,33 @@ Ruby::ShortUrl::Encoder.new.encode_url(123456) # => "00crI"
|
|
38
38
|
Ruby::ShortUrl::Encoder.new.decode_url("00crI") # => 123456
|
39
39
|
```
|
40
40
|
|
41
|
-
|
41
|
+
### Create your own short URL
|
42
|
+
|
43
|
+
```rb
|
44
|
+
class CustomEncoder < Ruby::ShortUrl::Encoder
|
45
|
+
def initialize
|
46
|
+
# Set your own custom alphabet and block_size
|
47
|
+
super(alphabet: "0123abc", block_size: 5)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# > custom_encoder = CustomEncoder.new
|
52
|
+
# => #<CustomEncoder:0x007faf3babc830 @alphabet="0123abc", @block_size=5, @mask=31, @mapping=[0, 1, 2, 3, 4]>
|
53
|
+
#
|
54
|
+
# > custom_encoder.encode_url(1)
|
55
|
+
# => "00022"
|
56
|
+
# > custom_encoder.encode_url(2)
|
57
|
+
# => "00011"
|
58
|
+
# > custom_encoder.encode_url(3)
|
59
|
+
# => "00033"
|
60
|
+
#
|
61
|
+
# > custom_encoder.decode_url("00022")
|
62
|
+
# => 1
|
63
|
+
# > custom_encoder.decode_url("00011")
|
64
|
+
# => 2
|
65
|
+
# > custom_encoder.decode_url("00033")
|
66
|
+
# => 3
|
67
|
+
```
|
42
68
|
|
43
69
|
## Development
|
44
70
|
|
@@ -7,7 +7,9 @@ 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 '
|
10
|
+
raise ArgumentError.new 'alphabet must contain at least 2 characters.' if alphabet.length < 2
|
11
|
+
raise ArgumentError.new 'block_size must be greater than 0.' unless block_size > 0
|
12
|
+
|
11
13
|
@alphabet = alphabet
|
12
14
|
@block_size = block_size
|
13
15
|
@mask = (1 << block_size) - 1
|
@@ -43,7 +45,7 @@ module Ruby
|
|
43
45
|
def debase(x)
|
44
46
|
n = @alphabet.length
|
45
47
|
x.split('').reverse.each_with_index.inject(0) do |result, (c, i)|
|
46
|
-
result
|
48
|
+
result + @alphabet.index(c) * (n ** i)
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
data/ruby-short_url.gemspec
CHANGED
@@ -16,8 +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.required_ruby_version = ">= 2.0.0"
|
20
|
+
|
19
21
|
spec.add_development_dependency "bundler"
|
20
|
-
spec.add_development_dependency "codeclimate-test-reporter"
|
22
|
+
spec.add_development_dependency "codeclimate-test-reporter", "~> 1.0"
|
21
23
|
spec.add_development_dependency "minitest"
|
22
24
|
spec.add_development_dependency "minitest-reporters"
|
23
25
|
spec.add_development_dependency "rake"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- toshi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: codeclimate-test-reporter
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '1.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
124
|
requirements:
|
125
125
|
- - ">="
|
126
126
|
- !ruby/object:Gem::Version
|
127
|
-
version:
|
127
|
+
version: 2.0.0
|
128
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
129
|
requirements:
|
130
130
|
- - ">="
|
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
132
|
version: '0'
|
133
133
|
requirements: []
|
134
134
|
rubyforge_project:
|
135
|
-
rubygems_version: 2.2
|
135
|
+
rubygems_version: 2.5.2
|
136
136
|
signing_key:
|
137
137
|
specification_version: 4
|
138
138
|
summary: Ruby implementation for generating Tiny URL. Ruby implementation of python-short_url.
|