Sha256: 1885233d7c25ba84688a7dbd5e4c4d1833294ffd4a4d78ee25771afe83df396b

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

require "email_inquire/helper"
require "email_inquire/response"
require "email_inquire/validator/common_provider"
require "email_inquire/validator/common_provider_mistake"
require "email_inquire/validator/commonly_mistaken_domain"
require "email_inquire/validator/commonly_mistaken_tld"
require "email_inquire/validator/country_code_tld"
require "email_inquire/validator/custom_invalid_domain"
require "email_inquire/validator/custom_valid_domain"
require "email_inquire/validator/email_format"
require "email_inquire/validator/known_invalid_domain"
require "email_inquire/validator/one_time_provider"
require "email_inquire/validator/unique_domain_provider"

module EmailInquire
  class Inquirer

    VALIDATORS = [
      # Format first
      EmailInquire::Validator::EmailFormat,

      # Custom overrides
      EmailInquire::Validator::CustomValidDomain,
      EmailInquire::Validator::CustomInvalidDomain,

      # Always valid domains
      EmailInquire::Validator::CommonProvider,

      # Invalid domains
      EmailInquire::Validator::KnownInvalidDomain,
      EmailInquire::Validator::OneTimeProvider,

      # Hints
      EmailInquire::Validator::CommonProviderMistake,
      EmailInquire::Validator::CommonlyMistakenDomain,
      EmailInquire::Validator::CommonlyMistakenTld,
      EmailInquire::Validator::CountryCodeTld,
      EmailInquire::Validator::UniqueDomainProvider,
    ].freeze

    def initialize(email)
      @email = email&.downcase
    end

    attr_reader :email

    def validate
      response = Helper.first_value(VALIDATORS) { |validator| validator.validate(email) }

      response || Response.new(email: email).valid!
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
email_inquire-0.11.0 lib/email_inquire/inquirer.rb