fat_fingers 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/fat_fingers.rb +32 -0
  2. data/tests/test_fat_fingers.rb +184 -0
  3. metadata +51 -0
@@ -0,0 +1,32 @@
1
+ class String
2
+
3
+ # Internal: Check a string for misspelled TLDs and
4
+ # misspelled domains from popular e-mail providers.
5
+ #
6
+ # Examples
7
+ #
8
+ # "joe@gmail.cmo".clean_up_typoed_email
9
+ # # => "joe@gmail.com"
10
+ #
11
+ # "joe@yaho.com".clean_up_typoed_email
12
+ # # => "joe@yahoo.com"
13
+ #
14
+ # Returns the cleaned String.
15
+ def clean_up_typoed_email
16
+ downcase.gsub(/c\.om$/, ".com")
17
+ .gsub(/n\.et$/, ".net")
18
+ .gsub(/\.com(.)*$/, ".com")
19
+ .gsub(/\.co[^op]$/, ".com")
20
+ .gsub(/(\.|\,|\'|\"|\\)*$/, "")
21
+ .gsub(/\.c*(c|i|l|m|n|o|p|0)*m+o*$/,".com")
22
+ .gsub(/\.(c|v|x)o+(m|n)$/,".com")
23
+ .gsub(/\.n*t*e*t*$/, ".net")
24
+ .gsub(/\.og*r*g*$/, ".org") #require the o, to not false-positive .gr e-mails
25
+ .gsub(/@coma*cas*t.net/,"@comcast.net")
26
+ .gsub(/@sbcgloba.net/, "@sbcglobal.net")
27
+ .gsub(/@gm*i*a*m*l*i*l*a*\./,"@gmail.")
28
+ .gsub(/@y*a*h*a*o*\./,"@yahoo.")
29
+ .gsub(/@h(o|p)*to*m*i*a*l*i*l*a*\./,"@hotmail.")
30
+ end
31
+
32
+ end
@@ -0,0 +1,184 @@
1
+ require 'minitest/autorun'
2
+ require 'fat_fingers'
3
+
4
+ class StringTest < MiniTest::Unit::TestCase
5
+ def setup
6
+ @good_gmail = "test@gmail.com"
7
+ @bad_gmail = [
8
+ "test@gmai.com",
9
+ "test@gmal.com",
10
+ "test@gmaal.com",
11
+ "test@gmil.com",
12
+ "test@gmial.com",
13
+ "test@gmali.com",
14
+ "test@gmila.com",
15
+ "test@gmaill.com",
16
+ "test@gamil.com",
17
+
18
+ "test@gmailc.om",
19
+ "test@gmail.coom",
20
+ "test@gmail.comm",
21
+ "test@gmail.comme",
22
+ "test@gmail.co,",
23
+ "test@gmail.co<",
24
+
25
+ "test@gmai.cmo",
26
+ "test@gmal.cmo",
27
+ "test@gmil.cmo",
28
+ "test@gmial.cmo",
29
+ "test@gmali.cmo",
30
+ "test@gmaill.cmo",
31
+ "test@gamil.cmo",
32
+
33
+ "test@gmai.cm",
34
+ "test@gmal.cm",
35
+ "test@gmil.cm",
36
+ "test@gmial.cm",
37
+ "test@gmali.cm",
38
+ "test@gmaill.cm",
39
+ "test@gamil.cm",
40
+
41
+ "test@gmai.om",
42
+ "test@gmal.om",
43
+ "test@gmil.om",
44
+ "test@gmial.om",
45
+ "test@gmali.om",
46
+ "test@gmaill.om",
47
+ "test@gamil.om",
48
+
49
+ "test@gmail.ocm",
50
+ "test@gmail.con",
51
+ "test@gmail.cmo",
52
+ "test@gmail.copm",
53
+ "test@gmail.xom",
54
+ "test@gmail.com,",
55
+ "test@gmail.com.",
56
+ "test@gmail.vom",
57
+ "test@gmail.comn",
58
+ "test@gmail.com'",
59
+ "test@gmail.com\"",
60
+ "test@gmail.com\\",
61
+ "test@gmail.comj",
62
+ "test@gmail.coim",
63
+ "test@gmail.cpm",
64
+ "test@gmail.colm",
65
+ "test@gmail.conm",
66
+ "test@gmail.coom",
67
+ "test@gmail.c0m",
68
+
69
+ "TEST@GMAIL.COM"
70
+ ]
71
+
72
+ @good_intl_gmail = "test@gmail.co.uk"
73
+ @bad_intl_gmail = [
74
+ "test@gmai.co.uk",
75
+ "test@gmal.co.uk",
76
+ "test@gmil.co.uk",
77
+ "test@gail.co.uk",
78
+ "test@gmali.co.uk",
79
+ "test@gmaill.co.uk",
80
+ "test@gamil.co.uk"
81
+ ]
82
+
83
+ @good_yahoo = "test@yahoo.com"
84
+ @bad_yahoo = [
85
+ "test@aho.com",
86
+ "test@ahoo.com",
87
+ "test@ahoo.cm",
88
+
89
+ "test@yaho.com",
90
+ "test@yahooo.com",
91
+ "test@yhao.com",
92
+ "test@yhaoo.com",
93
+ "test@yho.com",
94
+ "test@yhooo.com",
95
+ "test@yao.com",
96
+ "test@yaooo.com",
97
+ "test@yahooc.om",
98
+
99
+ "test@yaho.cm",
100
+ "test@yahooo.cm",
101
+ "test@yhao.cm",
102
+ "test@yhaoo.cm",
103
+ "test@yho.cm",
104
+ "test@yhooo.cm",
105
+ "test@yao.cm",
106
+ "test@yaooo.cm",
107
+
108
+ "test@yaho.om",
109
+ "test@yahooo.om",
110
+ "test@yhao.om",
111
+ "test@yhaoo.om",
112
+ "test@yho.om",
113
+ "test@yhooo.om",
114
+ "test@yao.om",
115
+ "test@yaooo.om"
116
+ ]
117
+
118
+ @good_hotmail = "test@hotmail.com"
119
+ @bad_hotmail = [
120
+ "test@hotmaill.com",
121
+ "test@hptmail.com",
122
+ "test@htomali.com"
123
+ ]
124
+
125
+ @good_net = "test@something.net"
126
+ @bad_net = [
127
+ "test@something.nt",
128
+ "test@something.ne",
129
+ "test@something.et",
130
+ "test@something.nte",
131
+ "test@something.nett"
132
+ ]
133
+
134
+ @good_org = "test@something.org"
135
+ @bad_org = [
136
+ "test@something.or",
137
+ "test@something.og",
138
+ "test@something.ogr",
139
+ "test@something.orgg"
140
+ ]
141
+
142
+ @good_comcast = "test@comcast.net"
143
+ @bad_comcast = [
144
+ "test@comacast.net",
145
+ "test@comcastn.et",
146
+ "test@comcat.net"
147
+ ]
148
+
149
+ @good_sbcglobal = "test@sbcglobal.net"
150
+ @bad_sbcglobal = [
151
+ "test@sbcgloba.net"
152
+ ]
153
+
154
+ @good_tld_cn = "test@something.cn"
155
+ @bad_tld_cn = ["test@something.cn"]
156
+
157
+ @good_tld_co = "test@something.co"
158
+ @bad_tld_co = ["test@something.co"]
159
+
160
+ @good_tld_gr = "test@something.gr"
161
+ @bad_tld_gr = ["test@something.gr"]
162
+
163
+ @good_tld_coop = "test@something.coop"
164
+ @bad_tld_coop = ["test@something.coop"]
165
+ end
166
+
167
+ def cases
168
+ ["gmail", "intl_gmail", "yahoo", "hotmail", "net", "org", "comcast", "sbcglobal", "tld_cn", "tld_co", "tld_gr", "tld_coop"]
169
+ end
170
+
171
+ def test_that_emails_get_fixed
172
+ cases.each do |test|
173
+ eval("@bad_"+test).each do |email|
174
+ assert_equal eval("@good_"+test), email.clean_up_typoed_email
175
+ end
176
+ end
177
+ end
178
+
179
+ def test_that_good_emails_do_not_get_broken
180
+ cases.each do |test|
181
+ assert_equal eval("@good_"+test), eval("@good_"+test).clean_up_typoed_email
182
+ end
183
+ end
184
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fat_fingers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Charlie Park
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-21 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Makes sure users don't accidentally create an account for the wrong e-mail
15
+ address. Because 'gmial' isn't actually what they meant to type. Similarly, 'yaho.com',
16
+ or the strange-but-true '.c0m'. Not even making that one up. If you're concerned
17
+ about false-positives, it's super-easy to check. There's only a single method. Also,
18
+ it's fully-tested.
19
+ email: charlie@charliepark.org
20
+ executables: []
21
+ extensions: []
22
+ extra_rdoc_files: []
23
+ files:
24
+ - lib/fat_fingers.rb
25
+ - tests/test_fat_fingers.rb
26
+ homepage: http://github.com/charliepark/fat_fingers
27
+ licenses: []
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.9.2
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 1.8.23
47
+ signing_key:
48
+ specification_version: 3
49
+ summary: Clean up e-mail strings when the user's made a typo (like 'gmail.cmo').
50
+ test_files:
51
+ - tests/test_fat_fingers.rb