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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: add30ce0a9800d2a6dd931d2989b781b1b688a31
4
- data.tar.gz: 5a3848ee4884d37a00a843a790e5484dbc448f7b
3
+ metadata.gz: e8ab1032da6a39eb445cfce821c89e2c7c461693
4
+ data.tar.gz: 829d03e252835c6df58ffa0965a853b3b9cc3cc4
5
5
  SHA512:
6
- metadata.gz: 3c044d20eb69742ea7ceb5945d3c7a6896c4734f7d621bfa4799060b47b6061ee19c5b07073a59fd8ae9244d98de9532b22ec3b992bf0e1ec1c01275bde3aad3
7
- data.tar.gz: 441ce0ad31c1b1bfeb8c8bd48d1650dd2732bc5db2201d096dde8d8aae64d56981346c05e4ec8392a34a8ec0c5505d9cfe7dcda1bdc98f93439bde80feceee9e
6
+ metadata.gz: 0fa0fdcbf10d2571ff2bae985189380a770ece3dbe06ae22aab7ee378f0a1accb6f89a2ebe085e9821f68091e9ccc92b2a293c3922dc18295935014bf1839f53
7
+ data.tar.gz: 64972d39fba9be3d4aca0baedcb942472357d9ece885689d3e84208a3c9155c32d248b840b13ed765f9d435d7e3db90f99cf04c4807f2b672dc9e290220f9e0d
data/.travis.yml CHANGED
@@ -3,3 +3,6 @@ rvm:
3
3
  - 2.2.0
4
4
  - 2.1.0
5
5
  - 2.0.0
6
+ addons:
7
+ code_climate:
8
+ repo_token: 357da37cbdcc472b4b33ba5f6e8a6fcc14ebcb41bb951b5133c547818ad6fbb3
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
@@ -1 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ task :default => :test
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << "test"
8
+ t.test_files = FileList["test/**/test_*.rb"]
9
+ end
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "ruby/short_url"
4
+ require "ruby-short_url"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -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=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 = 0
45
- x.split('').reverse.each_with_index do |c, i|
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 = 0
55
- @mapping.reverse.each_with_index do |b, i|
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 = 0
65
- @mapping.reverse.each_with_index do |b, i|
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
 
@@ -1,5 +1,5 @@
1
1
  module Ruby
2
2
  module ShortUrl
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -1,7 +1,2 @@
1
1
  require "ruby/short_url/version"
2
2
  require "ruby/short_url/encoder"
3
-
4
- module Ruby
5
- module ShortUrl
6
- end
7
- end
@@ -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", "~> 1.9"
20
- spec.add_development_dependency "rake", "~> 10.0"
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.1.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 00:00:00.000000000 Z
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: '1.9'
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: '1.9'
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: '10.0'
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: '10.0'
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/short_url.rb
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