base62-1.0.0/0000755000004100000410000000000012271517017012625 5ustar www-datawww-database62-1.0.0/Rakefile0000644000004100000410000000027712271517017014300 0ustar www-datawww-datarequire '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 => :testbase62-1.0.0/Gemfile0000644000004100000410000000013312271517017014115 0ustar www-datawww-datasource 'https://rubygems.org' # Specify your gem's dependencies in base62.gemspec gemspec base62-1.0.0/LICENSE.txt0000644000004100000410000000205512271517017014452 0ustar www-datawww-dataCopyright (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. base62-1.0.0/lib/0000755000004100000410000000000012271517017013373 5ustar www-datawww-database62-1.0.0/lib/base62/0000755000004100000410000000000012271517017014455 5ustar www-datawww-database62-1.0.0/lib/base62/string.rb0000644000004100000410000000010212271517017016301 0ustar www-datawww-dataclass String def base62_decode Base62.decode(self) end endbase62-1.0.0/lib/base62/version.rb0000644000004100000410000000004612271517017016467 0ustar www-datawww-datamodule Base62 VERSION = "1.0.0" end base62-1.0.0/lib/base62/integer.rb0000644000004100000410000000010312271517017016431 0ustar www-datawww-dataclass Integer def base62_encode Base62.encode(self) end endbase62-1.0.0/lib/base62.rb0000644000004100000410000000120112271517017014774 0ustar www-datawww-datarequire "base62/version" require "base62/string" require "base62/integer" 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 def encode(int) return "0" if int == 0 rem = int result = '' while rem != 0 result = PRIMITIVES[rem % PRIMITIVES.size].to_s + result rem /= PRIMITIVES.size end result end end endbase62-1.0.0/base62.gemspec0000644000004100000410000000215312271517017015255 0ustar www-datawww-datalib = 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@gmail.com", "lasse@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 base62-1.0.0/metadata.yml0000644000004100000410000000444612271517017015140 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: base62 version: !ruby/object:Gem::Version version: 1.0.0 platform: ruby authors: - JT Zemp - Lasse Bunk - Saadiq Rodgers-King - Derrick Camerino autorequire: bindir: bin cert_chain: [] 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@gmail.com - lasse@bunk.io executables: [] extensions: [] extra_rdoc_files: [] files: - .gitignore - CHANGELOG.md - Gemfile - LICENSE.txt - README.md - Rakefile - base62.gemspec - lib/base62.rb - lib/base62/integer.rb - lib/base62/string.rb - lib/base62/version.rb - test/base62_test.rb - test/test_helper.rb homepage: https://github.com/jtzemp/base62 licenses: - MIT metadata: {} post_install_message: rdoc_options: [] require_paths: - lib 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: 2.0.7 signing_key: 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 base62-1.0.0/test/0000755000004100000410000000000012271517017013604 5ustar www-datawww-database62-1.0.0/test/base62_test.rb0000644000004100000410000000215212271517017016252 0ustar www-datawww-datarequire "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 endbase62-1.0.0/test/test_helper.rb0000644000004100000410000000004412271517017016445 0ustar www-datawww-datarequire "base62" require "test/unit"base62-1.0.0/.gitignore0000644000004100000410000000002012271517017014605 0ustar www-datawww-data*.DS_Store *.gembase62-1.0.0/CHANGELOG.md0000644000004100000410000000050312271517017014434 0ustar www-datawww-data# 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) * Derrick Camerino added a Gemspec ## 0.1.1 (2009-11-4) * Ruby 1.9 compatible thx to Saadiq Rodgers-King ## 0.1.0 (2008-10-04) * 1 major enhancement: * Initial release base62-1.0.0/checksums.yaml.gz0000444000004100000410000000065212271517017016116 0ustar www-datawww-dataiR0y w)"_r Q`6[c%`[;C'fon7~ kҤu$|=o5Vn\QaRV;#v޵fbrS梽RRD*5 z®OCi&iC zr'`I._LP:>+Fne4v򅕳{SJ@~f2{(ِ=:hPVC6T Ė3:v 8ǯaW8,dԛq`KSR\뀦etV?f1%\KJ!W>sY]vEۋEH 1)eV0R2R3IWRv2vRabase62-1.0.0/README.md0000644000004100000410000000216312271517017014106 0ustar www-datawww-data# 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)