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