Sha256: e7e4e1daa0cc82073fc176d9118cc02d483a65dfedbb06f7419875ffc366c67f

Contents?: true

Size: 910 Bytes

Versions: 3

Compression:

Stored size: 910 Bytes

Contents

# frozen_string_literal: true
require "email_assessor/email_validator"

module EmailAssessor
  DISPOSABLE_DOMAINS_FILE_NAME = File.expand_path("../../vendor/disposable_domains.txt", __FILE__)
  BLACKLISTED_DOMAINS_FILE_NAME = File.expand_path("vendor/blacklisted_domains.txt")

  def self.domain_is_disposable?(domain)
    domain_in_file?(domain, DISPOSABLE_DOMAINS_FILE_NAME)
  end

  def self.domain_is_blacklisted?(domain)
    domain_in_file?(domain, BLACKLISTED_DOMAINS_FILE_NAME)
  end

  def self.domain_in_file?(domain, file_name)
    file_name ||= ""
    domain = domain.downcase

    File.foreach(file_name, chomp: true).any? do |line|
      # String#end_with? is used as a cheaper initial check but due to potential false positives
      # (hotmail.com is valid but tmail.com is not) regex is also necessary.
      domain.end_with?(line) && domain.match?(%r{\A(?:.*\.)?#{line}\z}i)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
email_assessor-0.7.1 lib/email_assessor.rb
email_assessor-0.7.0 lib/email_assessor.rb
email_assessor-0.6.0 lib/email_assessor.rb