Created
July 2, 2012 04:36
-
-
Save tsabat/3031128 to your computer and use it in GitHub Desktop.
slug.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Slug | |
def self.substituion | |
{ | |
'0' => 'c', | |
'1' => '0', | |
'2' => 'd', | |
'3' => '3', | |
'4' => 'p', | |
'5' => 'e', | |
'6' => 'n', | |
'7' => '2', | |
'8' => '3', | |
'9' => '4' | |
} | |
end | |
def self.encode number | |
Slug.sub number.to_s, Slug.substituion | |
end | |
def self.decode value | |
Slug.sub value, Slug.substituion.invert | |
end | |
private | |
def self.sub val, from | |
out = [] | |
val.to_s.each_char do |c| | |
out << from[c] | |
end | |
out.join | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment