fat_fingers 0.1.4 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fat_fingers.rb +66 -19
- data/test/test_fat_fingers.rb +67 -87
- metadata +1 -1
data/lib/fat_fingers.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class String
|
2
2
|
|
3
|
-
# Internal: Check a string for misspelled TLDs and misspelled domains from popular e-mail providers.
|
3
|
+
# Internal: Check a given string for misspelled TLDs and misspelled domains from popular e-mail providers.
|
4
4
|
#
|
5
5
|
# Examples
|
6
6
|
#
|
@@ -12,24 +12,71 @@ class String
|
|
12
12
|
#
|
13
13
|
# Returns the cleaned String.
|
14
14
|
def clean_up_typoed_email
|
15
|
-
downcase.
|
16
|
-
.
|
17
|
-
.
|
18
|
-
.
|
19
|
-
.
|
20
|
-
.
|
21
|
-
.
|
22
|
-
.
|
23
|
-
.
|
24
|
-
.
|
25
|
-
.
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
15
|
+
downcase.
|
16
|
+
remove_invalid_characters.
|
17
|
+
fix_transposed_periods.
|
18
|
+
fix_coms_with_appended_letters.
|
19
|
+
clean_up_funky_coms.
|
20
|
+
clean_up_funky_nets.
|
21
|
+
clean_up_funky_orgs.
|
22
|
+
clean_up_gmail.
|
23
|
+
clean_up_hotmail.
|
24
|
+
clean_up_yahoo.
|
25
|
+
clean_up_other_providers.
|
26
|
+
add_a_period_if_they_forgot_it
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def remove_invalid_characters
|
32
|
+
gsub(/(\s|\#|\'|\"|\\)*/, "").
|
33
|
+
gsub(/(\,|\.\.)/, ".").
|
34
|
+
gsub("@@", "@")
|
35
|
+
end
|
36
|
+
|
37
|
+
def fix_transposed_periods
|
38
|
+
gsub(/c\.om$/, ".com").
|
39
|
+
gsub(/n\.et$/, ".net")
|
40
|
+
# can't do "o.gr" => ".org", as ".gr" is a valid TLD
|
41
|
+
end
|
42
|
+
|
43
|
+
def fix_coms_with_appended_letters
|
44
|
+
gsub(/\.com(.)*$/, ".com").
|
45
|
+
gsub(/\.co[^op]$/, ".com")
|
46
|
+
end
|
47
|
+
|
48
|
+
def clean_up_funky_coms
|
49
|
+
gsub(/\.c*(c|i|l|m|n|o|p|0)*m+o*$/,".com").
|
50
|
+
gsub(/\.(c|v|x)o+(m|n)$/,".com")
|
51
|
+
end
|
52
|
+
|
53
|
+
def clean_up_funky_nets
|
54
|
+
gsub(/\.n*t*e*t*$/, ".net")
|
55
|
+
end
|
56
|
+
|
57
|
+
def clean_up_funky_orgs
|
58
|
+
gsub(/\.o+g*r*g*$/, ".org") # require the o, to not false-positive .gr e-mails
|
59
|
+
end
|
60
|
+
|
61
|
+
def clean_up_gmail
|
62
|
+
gsub(/@g(n|m)*(a|i|l)+m*(a|i|l)*\./,"@gmail.")
|
63
|
+
end
|
64
|
+
|
65
|
+
def clean_up_hotmail
|
66
|
+
gsub(/@h(o|p)*to*m*(a|i|l)*\./,"@hotmail.")
|
67
|
+
end
|
68
|
+
|
69
|
+
def clean_up_yahoo
|
70
|
+
gsub(/@y*a*h*a*o*\./,"@yahoo.")
|
71
|
+
end
|
72
|
+
|
73
|
+
def clean_up_other_providers
|
74
|
+
gsub(/@coma*cas*t.net/,"@comcast.net").
|
75
|
+
gsub(/@sbcgloba.net/, "@sbcglobal.net")
|
76
|
+
end
|
77
|
+
|
78
|
+
def add_a_period_if_they_forgot_it
|
79
|
+
gsub(/([^\.])(com|org|net)$/, '\1.\2')
|
33
80
|
end
|
34
81
|
|
35
82
|
end
|
data/test/test_fat_fingers.rb
CHANGED
@@ -15,88 +15,29 @@ class StringTest < MiniTest::Unit::TestCase
|
|
15
15
|
"test@gmila.com",
|
16
16
|
"test@gmaill.com",
|
17
17
|
"test@gamil.com",
|
18
|
-
|
19
|
-
"test@gmailc.om",
|
20
|
-
"test@gmail.coom",
|
21
|
-
"test@gmail.comm",
|
22
|
-
"test@gmail.comme",
|
23
|
-
"test@gmail.co,",
|
24
|
-
"test@gmail.co<",
|
25
|
-
|
26
|
-
"test@gmai.cmo",
|
27
|
-
"test@gmal.cmo",
|
28
|
-
"test@gmil.cmo",
|
29
|
-
"test@gmial.cmo",
|
30
|
-
"test@gmali.cmo",
|
31
|
-
"test@gmaill.cmo",
|
32
|
-
"test@gamil.cmo",
|
33
|
-
|
34
|
-
"test@gmai.cm",
|
35
|
-
"test@gmal.cm",
|
36
|
-
"test@gmil.cm",
|
37
|
-
"test@gmial.cm",
|
38
|
-
"test@gmali.cm",
|
39
|
-
"test@gmaill.cm",
|
40
|
-
"test@gamil.cm",
|
41
|
-
|
42
|
-
"test@gmai.om",
|
43
|
-
"test@gmal.om",
|
44
|
-
"test@gmil.om",
|
45
|
-
"test@gmial.om",
|
46
|
-
"test@gmali.om",
|
47
|
-
"test@gmaill.om",
|
48
|
-
"test@gamil.om",
|
49
|
-
|
50
|
-
"test@gmail.ocm",
|
51
|
-
"test@gmail.con",
|
52
|
-
"test@gmail.cmo",
|
53
|
-
"test@gmail.copm",
|
54
|
-
"test@gmail.xom",
|
55
|
-
"test@gmail.vom",
|
56
|
-
"test@gmail.comn",
|
57
|
-
"test@gmail.comj",
|
58
|
-
"test@gmail.coim",
|
59
|
-
"test@gmail.cpm",
|
60
|
-
"test@gmail.colm",
|
61
|
-
"test@gmail.conm",
|
62
|
-
"test@gmail.coom",
|
63
|
-
"test@gmail.c0m",
|
64
18
|
"test@gnail.com",
|
65
|
-
|
66
|
-
"te st@gmail.com",
|
67
|
-
|
68
|
-
"test@gmail.com'",
|
69
|
-
"te'st@gmail.com",
|
70
|
-
"test@gmail.com\"",
|
71
|
-
"test@gmail.com\\",
|
72
|
-
"test@gmail.com,",
|
73
|
-
"test@gmail.com.",
|
74
|
-
"test@gmail,com",
|
75
|
-
"test@#gmail.com",
|
76
|
-
"test\#@gmail.com",
|
77
|
-
"test@gmail..com",
|
78
|
-
#"test@gmailcom",
|
79
|
-
|
80
|
-
"TEST@GMAIL.COM"
|
19
|
+
"test@gmailc.om"
|
81
20
|
]
|
82
21
|
|
83
22
|
@good_intl_gmail = "test@gmail.co.uk"
|
84
23
|
@bad_intl_gmail = [
|
85
24
|
"test@gmai.co.uk",
|
86
25
|
"test@gmal.co.uk",
|
26
|
+
"test@gmaal.co.uk",
|
87
27
|
"test@gmil.co.uk",
|
88
|
-
"test@
|
28
|
+
"test@gmial.co.uk",
|
89
29
|
"test@gmali.co.uk",
|
30
|
+
"test@gmila.co.uk",
|
90
31
|
"test@gmaill.co.uk",
|
91
|
-
"test@gamil.co.uk"
|
32
|
+
"test@gamil.co.uk",
|
33
|
+
"test@gnail.co.uk",
|
92
34
|
]
|
93
35
|
|
94
36
|
@good_yahoo = "test@yahoo.com"
|
95
37
|
@bad_yahoo = [
|
96
38
|
"test@aho.com",
|
97
39
|
"test@ahoo.com",
|
98
|
-
"test@ahoo.
|
99
|
-
|
40
|
+
"test@ahoo.com",
|
100
41
|
"test@yaho.com",
|
101
42
|
"test@yahooo.com",
|
102
43
|
"test@yhao.com",
|
@@ -106,24 +47,6 @@ class StringTest < MiniTest::Unit::TestCase
|
|
106
47
|
"test@yao.com",
|
107
48
|
"test@yaooo.com",
|
108
49
|
"test@yahooc.om",
|
109
|
-
|
110
|
-
"test@yaho.cm",
|
111
|
-
"test@yahooo.cm",
|
112
|
-
"test@yhao.cm",
|
113
|
-
"test@yhaoo.cm",
|
114
|
-
"test@yho.cm",
|
115
|
-
"test@yhooo.cm",
|
116
|
-
"test@yao.cm",
|
117
|
-
"test@yaooo.cm",
|
118
|
-
|
119
|
-
"test@yaho.om",
|
120
|
-
"test@yahooo.om",
|
121
|
-
"test@yhao.om",
|
122
|
-
"test@yhaoo.om",
|
123
|
-
"test@yho.om",
|
124
|
-
"test@yhooo.om",
|
125
|
-
"test@yao.om",
|
126
|
-
"test@yaooo.om"
|
127
50
|
]
|
128
51
|
|
129
52
|
@good_hotmail = "test@hotmail.com"
|
@@ -133,6 +56,51 @@ class StringTest < MiniTest::Unit::TestCase
|
|
133
56
|
"test@htomali.com"
|
134
57
|
]
|
135
58
|
|
59
|
+
@good_com = "test@something.com"
|
60
|
+
@bad_com = [
|
61
|
+
"test@somethingc.om",
|
62
|
+
"test@something.coom",
|
63
|
+
"test@something.comm",
|
64
|
+
"test@something.comme",
|
65
|
+
"test@something.co,",
|
66
|
+
"test@something.co<",
|
67
|
+
"test@something.cmo",
|
68
|
+
"test@something.cm",
|
69
|
+
"test@something.om",
|
70
|
+
|
71
|
+
"test@something.ocm",
|
72
|
+
"test@something.con",
|
73
|
+
"test@something.cmo",
|
74
|
+
"test@something.copm",
|
75
|
+
"test@something.xom",
|
76
|
+
"test@something.vom",
|
77
|
+
"test@something.comn",
|
78
|
+
"test@something.comj",
|
79
|
+
"test@something.coim",
|
80
|
+
"test@something.cpm",
|
81
|
+
"test@something.colm",
|
82
|
+
"test@something.conm",
|
83
|
+
"test@something.coom",
|
84
|
+
"test@something.c0m",
|
85
|
+
|
86
|
+
"test@something.com'",
|
87
|
+
"te'st@something.com",
|
88
|
+
"test@something.com\"",
|
89
|
+
"test@something.com\\",
|
90
|
+
"test@something.com,",
|
91
|
+
"test@something.com.",
|
92
|
+
"test@something,com",
|
93
|
+
"test@\#something.com",
|
94
|
+
"test@#something.com",
|
95
|
+
"test@@something.com",
|
96
|
+
"test\#@something.com",
|
97
|
+
"test@something..com",
|
98
|
+
"test@somethingcom",
|
99
|
+
|
100
|
+
"te st@something.com",
|
101
|
+
"TEST@SOMETHING.COM"
|
102
|
+
]
|
103
|
+
|
136
104
|
@good_net = "test@something.net"
|
137
105
|
@bad_net = [
|
138
106
|
"test@something.nt",
|
@@ -140,7 +108,8 @@ class StringTest < MiniTest::Unit::TestCase
|
|
140
108
|
"test@something.et",
|
141
109
|
"test@something.nte",
|
142
110
|
"test@something.nett",
|
143
|
-
"test@something.net"
|
111
|
+
"test@something.net",
|
112
|
+
"test@somethingnet"
|
144
113
|
]
|
145
114
|
|
146
115
|
@good_org = "test@something.org"
|
@@ -148,7 +117,8 @@ class StringTest < MiniTest::Unit::TestCase
|
|
148
117
|
"test@something.or",
|
149
118
|
"test@something.og",
|
150
119
|
"test@something.ogr",
|
151
|
-
"test@something.orgg"
|
120
|
+
"test@something.orgg",
|
121
|
+
"test@somethingorg"
|
152
122
|
]
|
153
123
|
|
154
124
|
@good_comcast = "test@comcast.net"
|
@@ -163,6 +133,15 @@ class StringTest < MiniTest::Unit::TestCase
|
|
163
133
|
"test@sbcgloba.net"
|
164
134
|
]
|
165
135
|
|
136
|
+
@good_gm = "test@gm.com"
|
137
|
+
@bad_gm = ["test@gm.com"]
|
138
|
+
|
139
|
+
@good_gmail_with_dots = "te.st@gmail.com"
|
140
|
+
@bad_gmail_with_dots = ["te.st@gmail.com"]
|
141
|
+
|
142
|
+
@good_gmail_with_plus = "test+spamfilter@gmail.com"
|
143
|
+
@bad_gmail_with_plus = ["test+spamfilter@gmail.com"]
|
144
|
+
|
166
145
|
@good_tld_cn = "test@something.cn"
|
167
146
|
@bad_tld_cn = ["test@something.cn"]
|
168
147
|
|
@@ -174,10 +153,11 @@ class StringTest < MiniTest::Unit::TestCase
|
|
174
153
|
|
175
154
|
@good_tld_coop = "test@something.coop"
|
176
155
|
@bad_tld_coop = ["test@something.coop"]
|
156
|
+
|
177
157
|
end
|
178
158
|
|
179
159
|
def cases
|
180
|
-
["gmail", "intl_gmail", "yahoo", "hotmail", "net", "org", "comcast", "sbcglobal", "tld_cn", "tld_co", "tld_gr", "tld_coop"]
|
160
|
+
["gmail", "intl_gmail", "yahoo", "hotmail", "com", "net", "org", "comcast", "sbcglobal", "gm", "tld_cn", "tld_co", "tld_gr", "tld_coop", "gmail_with_dots", "gmail_with_plus"]
|
181
161
|
end
|
182
162
|
|
183
163
|
def test_that_emails_get_fixed
|