Class: HashValidator::Validator::EmailValidator

Inherits:
Base
  • Object
show all
Defined in:
lib/hash_validator/validators/email_validator.rb

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#should_validate?

Constructor Details

#initializeEmailValidator

Returns a new instance of EmailValidator.



2
3
4
# File 'lib/hash_validator/validators/email_validator.rb', line 2

def initialize
  super('email')  # The name of the validator
end

Instance Method Details

#presence_error_messageObject



6
7
8
# File 'lib/hash_validator/validators/email_validator.rb', line 6

def presence_error_message
  'is not a valid email'
end

#validate(key, value, _validations, errors) ⇒ Object



10
11
12
13
14
# File 'lib/hash_validator/validators/email_validator.rb', line 10

def validate(key, value, _validations, errors)
  unless value.is_a?(String) && value.include?("@")
    errors[key] = presence_error_message
  end
end