class String
Public Instance Methods
clean_up_typoed_email()
click to toggle source
Internal: Check a given string for misspelled TLDs and misspelled domains from popular e-mail providers.
Examples
"joe@gmail.cmo".clean_up_typoed_email # => "joe@gmail.com" "joe@yaho.com".clean_up_typoed_email # => "joe@yahoo.com"
Returns the cleaned String
.
# File lib/fat_fingers.rb, line 14 def clean_up_typoed_email downcase. remove_mailto. remove_invalid_characters. fix_transposed_periods. remove_period_around_at_sign. handle_different_country_tlds. fix_coms_with_appended_letters. clean_up_funky_coms. clean_up_funky_nets. clean_up_funky_orgs. clean_up_gmail. clean_up_googlemail. clean_up_hotmail. clean_up_aol. clean_up_yahoo. clean_up_other_providers. clean_up_known_coms. add_a_period_if_they_forgot_it end
Protected Instance Methods
add_a_period_if_they_forgot_it()
click to toggle source
# File lib/fat_fingers.rb, line 114 def add_a_period_if_they_forgot_it gsub(/([^\.])(com|org|net)$/, '\1.\2') end
clean_up_aol()
click to toggle source
# File lib/fat_fingers.rb, line 98 def clean_up_aol gsub(/@(ol|ao|ail)\./,"@aol.") end
clean_up_funky_coms()
click to toggle source
# File lib/fat_fingers.rb, line 69 def clean_up_funky_coms gsub(/\.c*(c|ck|ci|coi|l|m|n|o|op|cp|0|9)*m+o*$/,".com"). gsub(/\.(c|f|v|x|vc|xc)o+(m|n)$/,".com") end
clean_up_funky_nets()
click to toggle source
# File lib/fat_fingers.rb, line 74 def clean_up_funky_nets gsub(/\.(nte*|n*et*)$/, ".net") end
clean_up_funky_orgs()
click to toggle source
# File lib/fat_fingers.rb, line 78 def clean_up_funky_orgs gsub(/\.og?r?g{0,2}$/, ".org") # require the o, to not false-positive .gr e-mails end
clean_up_gmail()
click to toggle source
# File lib/fat_fingers.rb, line 86 def clean_up_gmail gsub(/@ga?e?i?o?r?g?[nm]{0,2}s?[ail]{1,2}[aiklmou]{0,3}\.(?!gov)(?!edu)(?!ac.in)/,"@gmail.") # match a broad variety of mispellings of gmail, but not if it's .gov or .edu end
clean_up_googlemail()
click to toggle source
# File lib/fat_fingers.rb, line 82 def clean_up_googlemail gsub(/@go{0,3}g{0,2}o?le?[mn]?[ail]{1,2}m?[aikl]{0,3}\.(?!gov)(?!edu)(?!ac.in)/,"@googlemail.") end
clean_up_hotmail()
click to toggle source
# File lib/fat_fingers.rb, line 90 def clean_up_hotmail gsub(/@h(i|o|p)?y?t?o?a?r?m?n?t?m?[aikl]{1,3}l?\./,"@hotmail.") end
clean_up_known_coms()
click to toggle source
# File lib/fat_fingers.rb, line 110 def clean_up_known_coms gsub(/(@aol|@googlemail|@gmail|@hotmail|@yahoo|@icloud|@outlook)\.(co|net|org)$/, '\1.com') end
clean_up_other_providers()
click to toggle source
# File lib/fat_fingers.rb, line 102 def clean_up_other_providers gsub(/@co?(m|n)a?cas?t{0,2}\./,"@comcast."). gsub(/@sbc?gl?ob[al]{0,2}l?\./, "@sbcglobal."). gsub(/@ver?i?z?on\./,"@verizon."). gsub(/@icl{0,2}o?u?d\./,"@icloud."). gsub(/@outl?ook?\./,"@outlook.") end
clean_up_yahoo()
click to toggle source
# File lib/fat_fingers.rb, line 94 def clean_up_yahoo gsub(/@(ya|yh|ua|ah)+h*a*o+\./,"@yahoo.") end
fix_coms_with_appended_letters()
click to toggle source
# File lib/fat_fingers.rb, line 62 def fix_coms_with_appended_letters gsub(/\.co[mn]\.com/, ".com"). gsub(/\.com\.$/, ".com"). gsub(/\.com(?!cast|\.|@).{1,3}$/, ".com"). # fix up to three extra letters after .com as long as they're not .comcast or .com.* (and as long as they're not before the @) gsub(/\.co[^op]$/, ".com") end
fix_transposed_periods()
click to toggle source
# File lib/fat_fingers.rb, line 47 def fix_transposed_periods gsub(/c\.om$/, ".com"). gsub(/n\.et$/, ".net") # can't do "o.gr" => ".org", as ".gr" is a valid TLD end
handle_different_country_tlds()
click to toggle source
# File lib/fat_fingers.rb, line 57 def handle_different_country_tlds gsub(/\.(o\.uk|couk|co\.um)$/, ".co.uk"). gsub(/\.(cojp|co\.lp)$/, ".co.jp") end
remove_invalid_characters()
click to toggle source
# File lib/fat_fingers.rb, line 41 def remove_invalid_characters gsub(/(\s|\#|\'|\"|\\)*/, ""). gsub(/(\,|\.\.)/, "."). gsub("@@", "@") end
remove_mailto()
click to toggle source
# File lib/fat_fingers.rb, line 37 def remove_mailto gsub(/\Amailto:/, "") end
remove_period_around_at_sign()
click to toggle source
# File lib/fat_fingers.rb, line 53 def remove_period_around_at_sign gsub(/(\.@|@\.)/, "@") end