Class: ValidEmail2::Address
- Inherits:
-
Object
- Object
- ValidEmail2::Address
- Defined in:
- lib/valid_email2/address.rb
Constant Summary collapse
- ALLOWED_DOMAIN_CHARACTERS_REGEX =
/\A[a-z0-9\-.]+\z/i
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
Instance Method Summary collapse
- #blacklisted? ⇒ Boolean
- #disposable? ⇒ Boolean
-
#initialize(address) ⇒ Address
constructor
A new instance of Address.
- #valid? ⇒ Boolean
- #valid_mx? ⇒ Boolean
Constructor Details
#initialize(address) ⇒ Address
Returns a new instance of Address.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/valid_email2/address.rb', line 11 def initialize(address) @parse_error = false @raw_address = address begin @address = Mail::Address.new(address) rescue Mail::Field::ParseError @parse_error = true end end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
7 8 9 |
# File 'lib/valid_email2/address.rb', line 7 def address @address end |
Instance Method Details
#blacklisted? ⇒ Boolean
44 45 46 |
# File 'lib/valid_email2/address.rb', line 44 def blacklisted? valid? && domain_is_in?(ValidEmail2.blacklist) end |
#disposable? ⇒ Boolean
40 41 42 |
# File 'lib/valid_email2/address.rb', line 40 def disposable? valid? && domain_is_in?(ValidEmail2.disposable_emails) end |
#valid? ⇒ Boolean
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/valid_email2/address.rb', line 22 def valid? return false if @parse_error if address.domain && address.address == @raw_address domain = address.domain domain.match(ALLOWED_DOMAIN_CHARACTERS_REGEX) && # Domain needs to have at least one dot domain.match(/\./) && # Domain may not have two consecutive dots !domain.match(/\.{2,}/) && # Domain may not start with a dot !domain.match(/^\./) else false end end |
#valid_mx? ⇒ Boolean
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/valid_email2/address.rb', line 48 def valid_mx? return false unless valid? mx = [] Resolv::DNS.open do |dns| mx.concat dns.getresources(address.domain, Resolv::DNS::Resource::IN::MX) end mx.any? end |