Skip to content

Commit

Permalink
Extract blacklisted? method for Ruby implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen Stephens committed Mar 21, 2016
1 parent 0461b2d commit 4afe036
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions platform/ruby/mail_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module MailChecker
def self.valid?(email)
return false unless valid_email?(email)

!extract_all_domain_suffixes(email).any? { |domain| BLACKLIST.include?(domain) }
!blacklisted?(email)
end

def self.valid_email?(email)
Expand All @@ -17,8 +17,12 @@ def self.valid_email?(email)
email =~ EMAIL_REGEX
end

def self.blacklisted?(email)
extract_all_domain_suffixes(email).any? { |domain| BLACKLIST.include?(domain) }
end

def self.extract_all_domain_suffixes(email)
domain = email.gsub(/.+@([^.]+)/, '\1').downcase
domain = email.to_s.gsub(/.+@([^.]+)/, '\1').downcase

domain_components = domain.split('.')

Expand Down
8 changes: 6 additions & 2 deletions platform/ruby/mail_checker.tmpl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module MailChecker
def self.valid?(email)
return false unless valid_email?(email)

!extract_all_domain_suffixes(email).any? { |domain| BLACKLIST.include?(domain) }
!blacklisted?(email)
end

def self.valid_email?(email)
Expand All @@ -17,8 +17,12 @@ def self.valid_email?(email)
email =~ EMAIL_REGEX
end

def self.blacklisted?(email)
extract_all_domain_suffixes(email).any? { |domain| BLACKLIST.include?(domain) }
end

def self.extract_all_domain_suffixes(email)
domain = email.gsub(/.+@([^.]+)/, '\1').downcase
domain = email.to_s.gsub(/.+@([^.]+)/, '\1').downcase

domain_components = domain.split('.')

Expand Down

0 comments on commit 4afe036

Please sign in to comment.