Class: SBOM::CycloneDX::Validator::EmailAddressValidator

Inherits:
BaseValidator
  • Object
show all
Defined in:
lib/sbom/cyclone_dx/validator/email_address_validator.rb

Constant Summary

Constants inherited from BaseValidator

BaseValidator::INVALID_TYPE, BaseValidator::MISSING_REQUIRED

Instance Method Summary collapse

Methods inherited from BaseValidator

#raw_types, #required?, #valid?

Constructor Details

#initialize(required: false) ⇒ EmailAddressValidator

Returns a new instance of EmailAddressValidator.



11
12
13
# File 'lib/sbom/cyclone_dx/validator/email_address_validator.rb', line 11

def initialize(required: false)
  super(EmailAddress::Address, String, required: required)
end

Instance Method Details

#validate(value) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sbom/cyclone_dx/validator/email_address_validator.rb', line 15

def validate(value)
  rv = super
  return rv unless value.is_a?(EmailAddress::Address) || value.is_a?(String)

  begin
    to_validate = value.is_a?(EmailAddress::Address) ? value : EmailAddress::Address.new(value)
    return rv if to_validate.valid?
  rescue NoMethodError
    # Do nothing, all errors handled below
  end

  rv << "Invalid email address"
end