Class: EmailDomainChecker::Normalizer
- Inherits:
-
Object
- Object
- EmailDomainChecker::Normalizer
- Defined in:
- lib/email_domain_checker/normalizer.rb
Class Method Summary collapse
Class Method Details
.idn_to_ascii(domain) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/email_domain_checker/normalizer.rb', line 20 def self.idn_to_ascii(domain) # Simple IDN conversion using built-in methods # For production, consider using the 'simpleidn' gem begin # Try to encode as IDN if it contains non-ASCII characters if domain.match?(/[^\x00-\x7F]/) # Fallback: return as-is if IDN conversion fails # In production, use: SimpleIDN.to_ascii(domain) domain else domain end rescue StandardError domain end end |
.normalize(raw) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/email_domain_checker/normalizer.rb', line 5 def self.normalize(raw) return "" if raw.nil? || raw.to_s.strip.empty? email_str = raw.to_s.strip return "" if email_str.empty? # Basic normalization: lowercase and IDN handling local, domain = email_str.downcase.split("@", 2) return email_str unless local && domain && !local.empty? && !domain.empty? # IDN (Internationalized Domain Name) conversion domain = idn_to_ascii(domain) "#{local}@#{domain}" end |