Skip to content

Commit

Permalink
Fixing constant to disallow period at beginning or end
Browse files Browse the repository at this point in the history
  • Loading branch information
golmansax committed Mar 19, 2015
1 parent eb6c5ba commit 8a51e5b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
21 changes: 15 additions & 6 deletions lib/email_repair/constants.rb
@@ -1,12 +1,21 @@
module EmailRepair
class Constants
def self.email_regex
local_part_regex = "[#{email_local_part_valid_chars}]+"
/#{local_part_regex}@(?:[a-z0-9\-]+\.)+(?:museum|travel|[a-z]{2,4})/
end
class << self
def email_regex
local_part_regex = "[#{valid_chars}]" \
"([#{valid_chars_with_dot}]*[#{valid_chars}])?"
/#{local_part_regex}@(?:[a-z0-9\-]+\.)+(?:museum|travel|[a-z]{2,4})/
end

private

def valid_chars_with_dot
"#{valid_chars}\."
end

def self.email_local_part_valid_chars
'a-z0-9_\.%\+\-\''
def valid_chars
'a-z0-9_%\+\-\''
end
end
end
end
5 changes: 2 additions & 3 deletions spec/lib/email_repair/mechanic_spec.rb
Expand Up @@ -2,7 +2,6 @@

module EmailRepair
describe Mechanic, '#repair' do

let(:mechanic) { Mechanic.new }

it 'returns clean emails as is' do
Expand All @@ -26,7 +25,7 @@ module EmailRepair
end

it 'returns nil for strings that have no email' do
['', ' ', 'NOT AN EMAIL', 'b at b dot com'].each do |not_email|
['', ' ', 'NOT AN EMAIL', 'b at b dot com', 'a.@com'].each do |not_email|
expect(mechanic.repair(not_email)).to be_nil
end
end
Expand Down Expand Up @@ -107,6 +106,7 @@ module EmailRepair
'one@email.com,another@email.com' => 'one@email.com',
'one@email.com;another@email.com' => 'one@email.com',
'<one@email.com>' => 'one@email.com',
'.one@email.com' => 'one@email.com',
}

dirty_emails.each do |in_mail, out_mail|
Expand All @@ -125,6 +125,5 @@ module EmailRepair
expect(mechanic.repair(in_mail)).to eq out_mail
end
end

end
end

0 comments on commit 8a51e5b

Please sign in to comment.