Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Base 10 ↔ Base 62 conversions.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 CHANGELOG.md
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 radix62.gemspec
README.md

Radix62

Convert integers to base 62 strings and back.

Base 62 includes the numbers 0-9 and characters A-Z (both lower and upper case). This can be useful for applications such as URL shorteners.

Installation

Just like any other gem:

gem install radix62

Usage

Two methods are provided, Radix62#encode62 and Radix62#decode62

require "radix62"
Radix62.encode62(1000)                          #=> "g8"
Radix62.encode62(9999999)                       #=> "FXsj"
Radix62.decode62("a")                           #=> "10"
Radix62.decode62("A")                           #=> "36"
Radix62.decode62("Abc123")                      #=> "33146185555"
Radix62.decode62(Radix62.encode62(1234567890))  #=> 1234567890

Radix62 also adds the decode62 and encode62 convenience methods to the String and Integer classes, respectively.

1000.encode62                                   #=> "g8"
"Abc123".decode62                               #=> "33146185555"

Tests and compatibility

Build Status Code Climate

The gem is tested against MRI 1.8/1.9/2.0, JRuby, and Rubinius. See Travis CI for details.

License

Licensed under the MIT license, see the LICENSE file for details.

Something went wrong with that request. Please try again.