Class: Philiprehberger::EmailValidator::Result

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

Overview

Value object representing the outcome of an email validation.

Examples:

result = EmailValidator.validate("user@example.com")
result.valid?   # => true
result.errors   # => []
result.warnings # => []

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(errors: [], warnings: []) ⇒ Result

Returns a new instance of Result.

Parameters:

  • errors (Array<String>) (defaults to: [])

    validation error messages

  • warnings (Array<String>) (defaults to: [])

    non-fatal warning messages



21
22
23
24
25
# File 'lib/philiprehberger/email_validator/result.rb', line 21

def initialize(errors: [], warnings: [])
  @errors = errors.freeze
  @warnings = warnings.freeze
  freeze
end

Instance Attribute Details

#errorsArray<String> (readonly)

Returns list of validation error messages.

Returns:

  • (Array<String>)

    list of validation error messages



14
15
16
# File 'lib/philiprehberger/email_validator/result.rb', line 14

def errors
  @errors
end

#warningsArray<String> (readonly)

Returns list of non-fatal warning messages.

Returns:

  • (Array<String>)

    list of non-fatal warning messages



17
18
19
# File 'lib/philiprehberger/email_validator/result.rb', line 17

def warnings
  @warnings
end

Instance Method Details

#to_sString Also known as: inspect

String representation for debugging.

Returns:

  • (String)


37
38
39
40
41
42
43
# File 'lib/philiprehberger/email_validator/result.rb', line 37

def to_s
  if valid?
    '#<EmailValidator::Result valid>'
  else
    "#<EmailValidator::Result invalid errors=#{@errors}>"
  end
end

#valid?Boolean

Whether the email passed all validation checks.

Returns:

  • (Boolean)


30
31
32
# File 'lib/philiprehberger/email_validator/result.rb', line 30

def valid?
  @errors.empty?
end