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 =
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
44 45 46 47 48 49 |
# File 'app/lib/free_email_domains.rb', line 44 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
54 55 56 57 |
# File 'app/lib/free_email_domains.rb', line 54 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
20 21 22 23 24 |
# File 'app/lib/free_email_domains.rb', line 20 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
31 32 33 |
# File 'app/lib/free_email_domains.rb', line 31 def list @list ||= load_domains end |
.reload! ⇒ Object
Force reload the list (useful for testing)
36 37 38 39 |
# File 'app/lib/free_email_domains.rb', line 36 def reload! @list = nil list end |