Created
July 1, 2011 16:40
-
-
Save newfront/1058896 to your computer and use it in GitHub Desktop.
Reverse and Dottify a Number for Enum
This file contains 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
#!/usr/bin/ruby | |
#5109926224 | |
#4226299015 | |
#4.2.2.6.2.9.9.0.1.5.1.e164.convorelay.com | |
#100 10 "u" "E2U+sip" "!^.*$!sip:[email protected]!". | |
raise "You need to add a 10D number to reverse and dottify as ARGV[0]" unless !ARGV.empty? | |
$num = ARGV[0] | |
def enum_reverse_dottify(num) | |
raise "You need to provide a 10D number" unless strip_keys(num).length == 10 | |
num = strip_keys(num) | |
count = 0 | |
return ((num.reverse).scan(/./).map{|val| val+"."}.join)+"1" | |
end | |
def strip_keys(num) | |
return num.to_s.gsub(/[\(\)\- ]/,'') | |
end | |
puts (enum_reverse_dottify($num)) | |
# usage: ruby reverse_dottify.rb '(925) 726-3439' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment