class EmailRepair::Mechanic::CommonDomainSwapRepair
Public Class Methods
repair(email)
click to toggle source
# File lib/email_repair/mechanic.rb, line 112 def self.repair(email) swapped_names.each do |swapped, real| suffix = common_domains[real] regex = /#{swapped}.#{suffix}$/ email = email.sub(regex, "#{real}.#{suffix}") if email.match(regex) end email end
swap_name(str)
click to toggle source
# File lib/email_repair/mechanic.rb, line 128 def self.swap_name(str) result = [] (str.length - 1).times do |pos| beginning = str[0...pos] middle = "#{str[pos + 1]}#{str[pos]}" the_end = str[(pos + 2)..-1] result << "#{beginning}#{middle}#{the_end}" end result end
swapped_names()
click to toggle source
# File lib/email_repair/mechanic.rb, line 121 def self.swapped_names @domain_keys ||= common_domains.keys @swapped_names ||= @domain_keys.each_with_object({}) do |name, result| swap_name(name).each { |swapped_name| result[swapped_name] = name } end end