Project

radix62

0.01
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Convert base 10 integers to base 62 strings (or base 62 strings to base 10 integers).
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
~> 2.12
 Project Readme

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/2.1, JRuby, and Rubinius. See Travis CI for details.

License

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