Class: EmailRepair::Mechanic::CommonDomainSwapRepair
- Inherits:
-
CommonDomainRepair
- Object
- CommonDomainRepair
- EmailRepair::Mechanic::CommonDomainSwapRepair
- Defined in:
- lib/email_repair/mechanic.rb
Class Method Summary collapse
Methods inherited from CommonDomainRepair
Class Method Details
.repair(email) ⇒ Object
112 113 114 115 116 117 118 119 |
# 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) ⇒ Object
128 129 130 131 132 133 134 135 136 137 |
# 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 ⇒ Object
121 122 123 124 125 126 |
# 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 |