Class: EmailInquire::EmailValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/email_inquire/email_validator.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email) ⇒ EmailValidator

Returns a new instance of EmailValidator.



9
10
11
# File 'lib/email_inquire/email_validator.rb', line 9

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

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



13
14
15
# File 'lib/email_inquire/email_validator.rb', line 13

def email
  @email
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
# File 'lib/email_inquire/email_validator.rb', line 15

def valid?
  return false unless email.count("@") == 1
  return false if email.length > 255
  name, domain = email.split("@", 2)

  name_valid?(name) && domain_valid?(domain)
end