diff --git a/.rubocop.yml b/.rubocop.yml index 826f079..9ee1c59 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -7,6 +7,9 @@ TrailingComma: AccessModifierIndentation: EnforcedStyle: outdent +MethodLength: + Max: 15 + CollectionMethods: PreferredMethods: collect: 'map' diff --git a/lib/email_repair/mechanic.rb b/lib/email_repair/mechanic.rb index 35adfd3..f4aecd1 100644 --- a/lib/email_repair/mechanic.rb +++ b/lib/email_repair/mechanic.rb @@ -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 diff --git a/spec/lib/email_repair/mechanic_spec.rb b/spec/lib/email_repair/mechanic_spec.rb index f9e13b3..c067c19 100644 --- a/spec/lib/email_repair/mechanic_spec.rb +++ b/spec/lib/email_repair/mechanic_spec.rb @@ -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 }