Skip to content

Commit

Permalink
Merge 16aca05 into 44365bd
Browse files Browse the repository at this point in the history
  • Loading branch information
QuotableWater7 committed Jun 28, 2016
2 parents 44365bd + 16aca05 commit 3d71d26
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ TrailingComma:
AccessModifierIndentation:
EnforcedStyle: outdent

MethodLength:
Max: 15

CollectionMethods:
PreferredMethods:
collect: 'map'
Expand Down
20 changes: 20 additions & 0 deletions lib/email_repair/mechanic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@ def repairs
]
end

def repair_all(emails)
sanitized_emails = []
invalid_emails = []

emails.each do |email|
repaired_email = repair(email)

if repaired_email
sanitized_emails << repaired_email
else
invalid_emails << email
end
end

OpenStruct.new(
sanitized_emails: sanitized_emails,
invalid_emails: invalid_emails,
)
end

def repair(email)
return unless email

Expand Down
15 changes: 15 additions & 0 deletions spec/lib/email_repair/mechanic_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
require 'spec_helper'

module EmailRepair
describe Mechanic, '#repair_all' do

it 'sanitizes an array of emails and returns bulk results' do
mechanic = Mechanic.new
salvageable_emails = %w(One@@two.com three@four.com)
sanitized_emails = %w(one@two.com three@four.com)
bad_emails = %w(bleep@blop plooooooop)

result = mechanic.repair_all(salvageable_emails + bad_emails)
expect(result.sanitized_emails).to match_array sanitized_emails
expect(result.invalid_emails).to match_array bad_emails
end

end

describe Mechanic, '#repair' do
let(:mechanic) { Mechanic.new }

Expand Down

0 comments on commit 3d71d26

Please sign in to comment.