Module: FreeEmailDomains
- Defined in:
- app/lib/free_email_domains.rb
Overview
Shared list of free/consumer email domains.
Used to identify personal email addresses vs business email addresses.
Constant Summary collapse
- DOMAINS_FILE =
Domains file.
Rails.root.join("data/free_email_domains.yml").freeze
Class Method Summary collapse
-
.domain_from_email(email) ⇒ String?
Extract domain from an email address.
-
.free_email?(email) ⇒ Boolean
Check if an email is from a free email provider.
-
.include?(domain) ⇒ Boolean
(also: free?, consumer?)
Check if a domain is a known free email provider.
-
.list ⇒ Array<String>
Get the full list of free email domains.
-
.reload! ⇒ Object
Force reload the list (useful for testing).
Class Method Details
.domain_from_email(email) ⇒ String?
Extract domain from an email address
45 46 47 48 49 50 |
# File 'app/lib/free_email_domains.rb', line 45 def domain_from_email(email) return nil if email.blank? parts = email.to_s.strip.downcase.split('@') parts.length == 2 ? parts.last : nil end |
.free_email?(email) ⇒ Boolean
Check if an email is from a free email provider
55 56 57 58 |
# File 'app/lib/free_email_domains.rb', line 55 def free_email?(email) domain = domain_from_email(email) domain.present? && include?(domain) end |
.include?(domain) ⇒ Boolean Also known as: free?, consumer?
Check if a domain is a known free email provider
21 22 23 24 25 |
# File 'app/lib/free_email_domains.rb', line 21 def include?(domain) return false if domain.blank? list.include?(domain.to_s.downcase.strip) end |
.list ⇒ Array<String>
Get the full list of free email domains
32 33 34 |
# File 'app/lib/free_email_domains.rb', line 32 def list @list ||= load_domains end |
.reload! ⇒ Object
Force reload the list (useful for testing)
37 38 39 40 |
# File 'app/lib/free_email_domains.rb', line 37 def reload! @list = nil list end |