Skip to content

Instantly share code, notes, and snippets.

@gf3
Created May 21, 2009
Embed
What would you like to do?
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