Created
May 21, 2009 16:20
-
-
Save gf3/115552 to your computer and use it in GitHub Desktop.
Get the absolute value of a phone number.
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
# 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