email_inquire 0.3.0 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33910bcf568803231698aa77ddb9eca49c793129
4
- data.tar.gz: 14cc507b4cf1d85d57886d70273c7e59f799bf23
3
+ metadata.gz: 14209d0b6b0f04fc0b236b425432cce860f0ef7f
4
+ data.tar.gz: b0a266ddf3aa51dfbb63e725fba356e6004040e9
5
5
  SHA512:
6
- metadata.gz: e046cccc9bb04c860eb16c8f09247b9217e11bf63a7484ac26c334afdab59dc97077f71c1c7c302df743f433d3a6f85c2e61eb167d19ccb8e962b67887560dc4
7
- data.tar.gz: c9ca590cd4169a068312a82e27c3db3ecedfb61f860ae3a5b46aa226271c9f599be4f6bc690a4a461bbbf46bab8fcdee19d1b4078fe5bc0c308f42076e04f6a5
6
+ metadata.gz: dccb794f40ba3360c7e1b7e547ccd1a164f5e7da65e8d66690b30ccf0f67a2cb6fbf06d6e94fe48d56146a2cd8d62d2ed4165f9b1e6da7ed45e080ed9932a187
7
+ data.tar.gz: e4b418ef9e26d1b041f363fb0e8c3aedf413904db5dfffd792d453a8b944176ffb86ac438dc916059035c15785183858e12dc7ca2eb02beacaff8d10fd8fd181
data/README.md CHANGED
@@ -6,13 +6,13 @@ EmailInquire is a library to validate email for common typos and one-time email
6
6
 
7
7
  ## Why?
8
8
 
9
- Before an user is an user, it's a visitor. And he must register to be so. What if he makes a typo while
10
- entering its email address during the registration ?
11
- If he didn't notice, you just lost him. He won't be able to sign in next time.
9
+ Before a user is a user, they are a visitor. And they must register to be so. What if they makes a typo while
10
+ entering their email address during the registration ?
11
+ If they didn't notice, you just lost them. They won't be able to sign in next time.
12
12
 
13
13
  Your users :
14
14
 
15
- - may not be as tech saavy as you;
15
+ - may not be as tech savvy as you;
16
16
  - may not remember exactly their email address;
17
17
  - may make a typo while typing their email address (very very common on a mobile keyboard).
18
18
 
@@ -151,4 +151,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/maxime
151
151
  ## License
152
152
 
153
153
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
154
-
data/data/jp_tld.txt ADDED
@@ -0,0 +1,9 @@
1
+ .ac.jp
2
+ .ad.jp
3
+ .co.jp
4
+ .ed.jp
5
+ .go.jp
6
+ .gr.jp
7
+ .lg.jp
8
+ .ne.jp
9
+ .or.jp
@@ -50,7 +50,7 @@ module EmailInquire
50
50
  :validate_common_domains,
51
51
  :validate_one_time_providers,
52
52
  :validate_common_domain_mistakes,
53
- :validate_uk_tld,
53
+ :validate_cc_tld,
54
54
  :validate_common_tld_mistakes,
55
55
  :validate_domains_with_unique_tld,
56
56
  ].freeze
@@ -96,6 +96,7 @@ module EmailInquire
96
96
  end
97
97
 
98
98
  COMMON_TLD_MISTAKES = {
99
+ ".cojp" => ".co.jp",
99
100
  ".couk" => ".co.uk",
100
101
  ".com.com" => ".com",
101
102
  }.freeze
@@ -111,21 +112,28 @@ module EmailInquire
111
112
  end
112
113
  end
113
114
 
115
+ VALID_JP_TLD = load_data("jp_tld").freeze
114
116
  VALID_UK_TLD = load_data("uk_tld").freeze
117
+ VALID_CC_TLDs = [
118
+ [".jp", ".co.jp", VALID_JP_TLD],
119
+ [".uk", ".co.uk", VALID_UK_TLD],
120
+ ].freeze
115
121
 
116
- def validate_uk_tld
117
- return unless domain.end_with?(".uk")
118
-
119
- return if VALID_UK_TLD.any? do |reference|
120
- domain.end_with?(reference)
121
- end
122
+ def validate_cc_tld
123
+ VALID_CC_TLDs.each do |tld, sld, valid_tld|
124
+ next unless domain.end_with?(tld)
122
125
 
123
- new_domain = domain.dup
124
- new_domain.gsub!(/\.[a-z]{2}\.uk\z/, ".co.uk")
125
- new_domain.gsub!(/(?<!\.)co\.uk\z/, ".co.uk")
126
- new_domain.gsub!(/(?<!\.co)\.uk\z/, ".co.uk")
126
+ next if valid_tld.any? do |reference|
127
+ domain.end_with?(reference)
128
+ end
127
129
 
128
- response.hint!(domain: new_domain) if new_domain != domain
130
+ new_domain = domain.dup
131
+ tld_without_dot = tld[1..-1]
132
+ new_domain.gsub!(/\.[a-z]{2}\.#{tld_without_dot}\z/, sld)
133
+ new_domain.gsub!(/(?<!\.)co\.#{tld_without_dot}\z/, sld)
134
+ new_domain.gsub!(/(?<!\.co)\.#{tld_without_dot}\z/, sld)
135
+ response.hint!(domain: new_domain) if new_domain != domain
136
+ end
129
137
  end
130
138
 
131
139
  UNIQUE_TLD_DOMAINS = load_data("unique_domain_providers").freeze
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module EmailInquire
3
3
 
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
 
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_inquire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maxime Garcia
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-21 00:00:00.000000000 Z
11
+ date: 2017-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: damerau-levenshtein
@@ -99,6 +99,7 @@ files:
99
99
  - bin/console
100
100
  - bin/setup
101
101
  - data/common_providers.txt
102
+ - data/jp_tld.txt
102
103
  - data/one_time_email_providers.txt
103
104
  - data/uk_tld.txt
104
105
  - data/unique_domain_providers.txt