module Dhfex

  class Validator

    def initialize(number)
      @number = number
    end

    def detect_mail
      return nil if @number.nil?

      mails.each do |mail|
        number = "#{mail}::Validator".constantize.new(@number)
        return mail if number.valid?
      end
      nil
    end

    def mails
      namespace = "Dhfex::Mails"
      "#{namespace}".constantize.constants.map{|x| "#{namespace}::#{x}".constantize }.reject{|x| !x.kind_of?(Module) }
    end

  end

end
