Skip to content

Instantly share code, notes, and snippets.

@gf3
Created May 21, 2009 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gf3/115552 to your computer and use it in GitHub Desktop.
Save gf3/115552 to your computer and use it in GitHub Desktop.
Get the absolute value of a phone number.
# Get the absolute value of a phone number
def abs_phone(phone)
abs = []
phone = phone.gsub(/[^a-zA-Z0-9]/, '').downcase
phone.each_byte do |b|
case b
when 0..96
abs << (b - 48)
when 122
abs << ((((b-97).to_f/3.0)+1.0).round)
when 115..121
abs << ((((b-96).to_f/3.0)+1.0).round)
else
abs << ((((b-95).to_f/3.0)+1.0).round)
end
end
abs.join('')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment