base62 0.1.4 → 1.0.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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MTE4N2NmZmQ2ZjAyMzBlZjFjNjg1ZTVlNGRlMDljYTlhMDc4ZTk0OQ==
5
+ data.tar.gz: !binary |-
6
+ M2MzMzE0N2I5YTUxMmRiMGIyZjJiODlmZmZmOWE2Nzk5MjJhYTJjMg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ OTYzZmE5ZjdjYjM4NjU5YTc3MWZkNDg4Y2VlZGI4Y2U3ZDQwYzVhZDY0MGNj
10
+ NWM1NmU1NTQ4MjZmOTRhYWQ1M2Y5MjNjZjk4MWIxNjg5YmM4M2I4Mzk3MmUz
11
+ MmQxMzVjMDg1ZDhiZDY0NWJkZGU4N2ExNmNmMjE4N2Q5YjBiMDc=
12
+ data.tar.gz: !binary |-
13
+ NzIyZGMzMGE0ZmNiZDE5NTY0ZDkwMmI4ZjdhODRmY2EwOTdiNDU4OWVmNTI4
14
+ YzAwNjUxYTRjNjU4OTc0YmE2ZmFjOWI4OGI1MGVhNDgxZDQ3ZWM1YTYzMDc5
15
+ YWYyMDRjNWYxYTRkYmIwYjdhY2IxZmQwMzE4MjdhYTJkYjQ2NTU=
@@ -0,0 +1,2 @@
1
+ *.DS_Store
2
+ *.gem
@@ -1,16 +1,18 @@
1
- == 0.1.3 2010-11-24
1
+ # Base62 changelog
2
+
3
+ ## 0.1.3 (2010-11-24)
2
4
 
3
5
  * Cleaned out the crap that's not needed like hoe and rake tasks and newgem stuff
4
6
 
5
- == 0.1.2 2010-11-24
7
+ ## 0.1.2 (2010-11-24)
6
8
 
7
9
  * Derrick Camerino added a Gemspec
8
10
 
9
- == 0.1.1 2009-11-4
11
+ ## 0.1.1 (2009-11-4)
10
12
 
11
13
  * Ruby 1.9 compatible thx to Saadiq Rodgers-King
12
14
 
13
- == 0.1.0 2008-10-04
15
+ ## 0.1.0 (2008-10-04)
14
16
 
15
17
  * 1 major enhancement:
16
18
  * Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in base62.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2008-2014 JT Zemp
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # Base62
2
+
3
+ Base62 monkeypatches Integer to add an Integer#base62_encode instance method to encode an integer in the character set of 0-9 + A-Z + a-z. It also monkeypatches String to add String#base62_decode to take the string and turn it back into a valid integer.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ $ gem install base62
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ruby
14
+ require 'base62'
15
+
16
+ 123.base62_encode
17
+ # => "1z"
18
+
19
+ "funky".base62_decode
20
+ # => 619367412
21
+ ```
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork the project
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new pull request
30
+
31
+ ## Thanks
32
+
33
+ * [Lasse Bunk](https://github.com/lassebunk) for totally refactoring everything and bringing it into the modern age.
34
+ * [Saadiq Rodgers-King](http://github.com/saadiq) for making it work with Ruby 1.9.
35
+ * [Derrick Camerino](https://github.com/robustdj) for adding a Gemspec and prompting me to clean stuff up.
36
+
37
+ Copyright (c) 2008-2014 [JT Zemp](https://github.com/jtzemp), released under the [MIT License](https://github.com/jtzemp/base62/blob/master/LICENSE.txt)
@@ -0,0 +1,10 @@
1
+ require 'rake/testtask'
2
+ require 'bundler/gem_tasks'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.test_files = FileList['test/**/*_test.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,25 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'base62/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "base62"
7
+ s.version = Base62::VERSION
8
+ s.authors = ["JT Zemp", "Lasse Bunk", "Saadiq Rodgers-King", "Derrick Camerino"]
9
+ s.email = ["jtzemp@gmail.com", "lasse@bunk.io"]
10
+ s.description = %q{Base62 monkeypatches Integer to add an Integer#base62_encode
11
+ instance method to encode an integer in the character set of
12
+ 0-9 + A-Z + a-z. It also monkeypatches String to add
13
+ String#base62_decode to take the string and turn it back
14
+ into a valid integer.}
15
+ s.summary = %q{Monkeypatches Integer and String to allow for base62 encoding and decoding.}
16
+ s.homepage = "https://github.com/jtzemp/base62"
17
+ s.license = "MIT"
18
+
19
+ s.files = `git ls-files`.split($/)
20
+ s.test_files = s.files.grep(%r{^test/})
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_development_dependency "bundler", "~> 1.3"
24
+ s.add_development_dependency "rake"
25
+ end
@@ -1,95 +1,30 @@
1
- require File.dirname(__FILE__) + "/base62/version"
1
+ require "base62/version"
2
+ require "base62/string"
3
+ require "base62/integer"
2
4
 
3
- class String
4
- BASE62_PRIMITIVES = {
5
- "0" => 0,
6
- "1" => 1,
7
- "2" => 2,
8
- "3" => 3,
9
- "4" => 4,
10
- "5" => 5,
11
- "6" => 6,
12
- "7" => 7,
13
- "8" => 8,
14
- "9" => 9,
15
- "A" => 10,
16
- "B" => 11,
17
- "C" => 12,
18
- "D" => 13,
19
- "E" => 14,
20
- "F" => 15,
21
- "G" => 16,
22
- "H" => 17,
23
- "I" => 18,
24
- "J" => 19,
25
- "K" => 20,
26
- "L" => 21,
27
- "M" => 22,
28
- "N" => 23,
29
- "O" => 24,
30
- "P" => 25,
31
- "Q" => 26,
32
- "R" => 27,
33
- "S" => 28,
34
- "T" => 29,
35
- "U" => 30,
36
- "V" => 31,
37
- "W" => 32,
38
- "X" => 33,
39
- "Y" => 34,
40
- "Z" => 35,
41
- "a" => 36,
42
- "b" => 37,
43
- "c" => 38,
44
- "d" => 39,
45
- "e" => 40,
46
- "f" => 41 ,
47
- "g" => 42 ,
48
- "h" => 43 ,
49
- "i" => 44 ,
50
- "j" => 45 ,
51
- "k" => 46 ,
52
- "l" => 47 ,
53
- "m" => 48 ,
54
- "n" => 49 ,
55
- "o" => 50,
56
- "p" => 51,
57
- "q" => 52,
58
- "r" => 53,
59
- "s" => 54,
60
- "t" => 55,
61
- "u" => 56,
62
- "v" => 57,
63
- "w" => 58,
64
- "x" => 59,
65
- "y" => 60,
66
- "z" => 61
67
- }
68
-
69
- def base62_decode
70
- i = 0
71
- i_out = 0
72
- self.split(//).reverse.each do |c|
73
- place = BASE62_PRIMITIVES.size ** i
74
- i_out += BASE62_PRIMITIVES[c] * place
75
- i += 1
5
+ module Base62
6
+ PRIMITIVES = (0..9).collect { |i| i.to_s } + ('A'..'Z').to_a + ('a'..'z').to_a
7
+
8
+ class << self
9
+ def decode(str)
10
+ out = 0
11
+ str.split(//).reverse.each_with_index do |char, index|
12
+ place = PRIMITIVES.size ** index
13
+ out += PRIMITIVES.index(char) * place
14
+ end
15
+ out
76
16
  end
77
- i_out
78
- end
79
- end
80
17
 
18
+ def encode(int)
19
+ return "0" if int == 0
81
20
 
82
- class Integer
83
- BASE62_PRIMITIVES = (0..9).collect { |i| i.to_s } + ('A'..'Z').to_a + ('a'..'z').to_a
84
-
85
- def base62_encode
86
- return "0" if self == 0
87
- number = self
88
- result = ''
89
- while(number != 0)
90
- result = BASE62_PRIMITIVES[number % BASE62_PRIMITIVES.size ].to_s + result
91
- number /= BASE62_PRIMITIVES.size
92
- end
93
- result
21
+ rem = int
22
+ result = ''
23
+ while rem != 0
24
+ result = PRIMITIVES[rem % PRIMITIVES.size].to_s + result
25
+ rem /= PRIMITIVES.size
26
+ end
27
+ result
28
+ end
94
29
  end
95
- end
30
+ end
@@ -0,0 +1,5 @@
1
+ class Integer
2
+ def base62_encode
3
+ Base62.encode(self)
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class String
2
+ def base62_decode
3
+ Base62.decode(self)
4
+ end
5
+ end
@@ -1,7 +1,3 @@
1
1
  module Base62
2
- MAJOR = 0
3
- MINOR = 1
4
- TINY = 4
5
-
6
- VERSION = [MAJOR, MINOR, TINY].join('.')
2
+ VERSION = "1.0.0"
7
3
  end
@@ -0,0 +1,52 @@
1
+ require "test_helper"
2
+
3
+ class Base62Test < Test::Unit::TestCase
4
+ def test_encode
5
+ { 0 => "0",
6
+ 1 => "1",
7
+ 10 => "A",
8
+ 100 => "1c",
9
+ 1231 => "Jr",
10
+ 3982 => "12E",
11
+ 10927 => "2qF",
12
+ 50923 => "DFL",
13
+ 100292 => "Q5c",
14
+ 202731 => "qjr",
15
+ 519278 => "2B5S",
16
+ 902323 => "3mjb",
17
+ 1003827 => "4D8l",
18
+ 2129387 => "8vwx",
19
+ 52338283 => "3XbZr",
20
+ 298372887 => "KBwPv",
21
+ 8237468237 => "8zTZmv",
22
+ 256352386723872 => "1AnE6bpNA"
23
+ }.each do |int, base62|
24
+ assert_equal base62, int.base62_encode
25
+ end
26
+ end
27
+
28
+ def test_decode
29
+ { "" => 0,
30
+ "0" => 0,
31
+ "1" => 1,
32
+ "A" => 10,
33
+ "1c" => 100,
34
+ "Jr" => 1231,
35
+ "12E" => 3982,
36
+ "2qF" => 10927,
37
+ "DFL" => 50923,
38
+ "Q5c" => 100292,
39
+ "qjr" => 202731,
40
+ "2B5S" => 519278,
41
+ "3mjb" => 902323,
42
+ "4D8l" => 1003827,
43
+ "8vwx" => 2129387,
44
+ "3XbZr" => 52338283,
45
+ "KBwPv" => 298372887,
46
+ "8zTZmv" => 8237468237,
47
+ "1AnE6bpNA" => 256352386723872
48
+ }.each do |base62, int|
49
+ assert_equal int, base62.base62_decode
50
+ end
51
+ end
52
+ end
@@ -1,2 +1,2 @@
1
- require 'test/unit'
2
- require File.dirname(__FILE__) + '/../lib/base62'
1
+ require "base62"
2
+ require "test/unit"
metadata CHANGED
@@ -1,81 +1,94 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: base62
3
- version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 4
10
- version: 0.1.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - JT Zemp
8
+ - Lasse Bunk
14
9
  - Saadiq Rodgers-King
15
10
  - Derrick Camerino
16
11
  autorequire:
17
12
  bindir: bin
18
13
  cert_chain: []
19
-
20
- date: 2010-11-24 00:00:00 -07:00
21
- default_executable:
22
- dependencies: []
23
-
24
- description: |-
25
- Base62 monkeypatches Integer to add an Integer#base62_encode
26
- instance method to encode an integer in the character set of
27
- 0-9 + A-Z + a-z. It also monkeypatches String to add
28
- String#base62_decode to take the string and turn it back
29
- into a valid integer.
30
- email: jtzemp@gmail.com
14
+ date: 2014-01-16 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: bundler
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '1.3'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ description: ! "Base62 monkeypatches Integer to add an Integer#base62_encode\n instance
45
+ method to encode an integer in the character set of\n 0-9
46
+ + A-Z + a-z. It also monkeypatches String to add\n String#base62_decode
47
+ to take the string and turn it back\n into a valid integer."
48
+ email:
49
+ - jtzemp@gmail.com
50
+ - lasse@bunk.io
31
51
  executables: []
32
-
33
52
  extensions: []
34
-
35
53
  extra_rdoc_files: []
36
-
37
- files:
38
- - History.txt
39
- - README.rdoc
40
- - README.txt
41
- - lib/base62/version.rb
54
+ files:
55
+ - .gitignore
56
+ - CHANGELOG.md
57
+ - Gemfile
58
+ - LICENSE.txt
59
+ - README.md
60
+ - Rakefile
61
+ - base62.gemspec
42
62
  - lib/base62.rb
43
- - test/test_base62.rb
63
+ - lib/base62/integer.rb
64
+ - lib/base62/string.rb
65
+ - lib/base62/version.rb
66
+ - test/base62_test.rb
44
67
  - test/test_helper.rb
45
- has_rdoc: true
46
- homepage: http://github.com/jtzemp/base62
47
- licenses:
68
+ homepage: https://github.com/jtzemp/base62
69
+ licenses:
48
70
  - MIT
71
+ metadata: {}
49
72
  post_install_message:
50
73
  rdoc_options: []
51
-
52
- require_paths:
74
+ require_paths:
53
75
  - lib
54
- required_ruby_version: !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
- version: "0"
63
- required_rubygems_version: !ruby/object:Gem::Requirement
64
- none: false
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- hash: 3
69
- segments:
70
- - 0
71
- version: "0"
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
72
86
  requirements: []
73
-
74
87
  rubyforge_project:
75
- rubygems_version: 1.3.7
88
+ rubygems_version: 2.0.7
76
89
  signing_key:
77
- specification_version: 3
78
- summary: Base62 monkeypatches Integer to add an Integer#base62_encode instance method to encode an integer in the character set of 0-9 + A-Z + a-z. It also monkeypatches String to add String#base62_decode to take the string and turn it back into a valid integer.
79
- test_files:
80
- - test/test_base62.rb
90
+ specification_version: 4
91
+ summary: Monkeypatches Integer and String to allow for base62 encoding and decoding.
92
+ test_files:
93
+ - test/base62_test.rb
81
94
  - test/test_helper.rb
@@ -1,47 +0,0 @@
1
- == DESCRIPTION:
2
-
3
- Base62 monkeypatches Integer to add an Integer#base62_encode instance method to encode an integer in the character set of 0-9 + A-Z + a-z. It also monkeypatches String to add String#base62_decode to take the string and turn it back into a valid integer.
4
-
5
- == INSTALL:
6
-
7
- * sudo gem install base62
8
-
9
- == USAGE:
10
-
11
- require 'base62'
12
-
13
- 123.base62_encode
14
- => "1z"
15
-
16
- "funky".base62_decode
17
- => 619367412
18
-
19
- == THANKS:
20
-
21
- * Saadiq Rodgers-King (http://github.com/saadiq) for making it work with Ruby 1.9.
22
- * Derrick Camerino (https://github.com/robustdj) for adding a Gemspec and prompting me to clean stuff up.
23
-
24
- == LICENSE:
25
-
26
- (The MIT License)
27
-
28
- Copyright (c) 2008 JT Zemp & Thrive Information Solutions
29
-
30
- Permission is hereby granted, free of charge, to any person obtaining
31
- a copy of this software and associated documentation files (the
32
- 'Software'), to deal in the Software without restriction, including
33
- without limitation the rights to use, copy, modify, merge, publish,
34
- distribute, sublicense, and/or sell copies of the Software, and to
35
- permit persons to whom the Software is furnished to do so, subject to
36
- the following conditions:
37
-
38
- The above copyright notice and this permission notice shall be
39
- included in all copies or substantial portions of the Software.
40
-
41
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
42
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
43
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
44
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
45
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
46
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
47
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.txt DELETED
@@ -1,47 +0,0 @@
1
- == DESCRIPTION:
2
-
3
- Base62 monkeypatches Integer to add an Integer#base62_encode instance method to encode an integer in the character set of 0-9 + A-Z + a-z. It also monkeypatches String to add String#base62_decode to take the string and turn it back into a valid integer.
4
-
5
- == INSTALL:
6
-
7
- * sudo gem install base62
8
-
9
- == USAGE:
10
-
11
- require 'base62'
12
-
13
- 123.base62_encode
14
- => "1z"
15
-
16
- "funky".base62_decode
17
- => 619367412
18
-
19
- == THANKS:
20
-
21
- * Saadiq Rodgers-King (http://github.com/saadiq) for making it work with Ruby 1.9.
22
- * Derrick Camerino (https://github.com/robustdj) for adding a Gemspec and prompting me to clean stuff up.
23
-
24
- == LICENSE:
25
-
26
- (The MIT License)
27
-
28
- Copyright (c) 2008 JT Zemp & Thrive Information Solutions
29
-
30
- Permission is hereby granted, free of charge, to any person obtaining
31
- a copy of this software and associated documentation files (the
32
- 'Software'), to deal in the Software without restriction, including
33
- without limitation the rights to use, copy, modify, merge, publish,
34
- distribute, sublicense, and/or sell copies of the Software, and to
35
- permit persons to whom the Software is furnished to do so, subject to
36
- the following conditions:
37
-
38
- The above copyright notice and this permission notice shall be
39
- included in all copies or substantial portions of the Software.
40
-
41
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
42
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
43
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
44
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
45
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
46
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
47
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,17 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- class TestBase62 < Test::Unit::TestCase
4
-
5
- def test_1_to_100000
6
- (0..100000).each do |i|
7
- assert_equal(i.to_s, i.base62_encode.base62_decode.to_s, i.to_s + "\t" + i.base62_encode.to_s + "\t" + i.base62_encode.base62_decode.to_s)
8
- end
9
- end
10
-
11
- def test_0
12
- assert_equal(0, "0".base62_decode)
13
- assert_equal("0", 0.base62_encode)
14
- assert_equal(0, "".base62_decode)
15
- end
16
-
17
- end