Class: RegexForms::ValidateEmail

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email) ⇒ ValidateEmail

Returns a new instance of ValidateEmail.



109
110
111
# File 'lib/regex_forms.rb', line 109

def initialize(email)
  @email = email
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



107
108
109
# File 'lib/regex_forms.rb', line 107

def email
  @email
end

Instance Method Details

#validateEmailObject



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/regex_forms.rb', line 114

def validateEmail
  return invalid_response("Email is nil, empty") if invalid_email

  regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

  if regex.match(email)
    valid_response("Validated Email")
  else
    invalid_response("Must be a valid email address: #{email}")
  end
end