Skip to content

Instantly share code, notes, and snippets.

@tsabat
Created July 2, 2012 04:36
Show Gist options
  • Save tsabat/3031128 to your computer and use it in GitHub Desktop.
Save tsabat/3031128 to your computer and use it in GitHub Desktop.
slug.rb
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