Class: RubyEmail::Core

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

Overview

Abstract class to inherit and complete by adding the REGEXP constant

Direct Known Subclasses

Rfc1123, Rfc5322

Class Method Summary collapse

Class Method Details

.match(str) ⇒ MatchData or NilClass

Check if the string is a valid email and details how

Parameters:

Returns:

  • (MatchData or NilClass)

    matched email with the keys “local” and “domain”

Raises:

  • (ArgumentError)

    if str is not a String



17
18
19
20
# File 'lib/ruby_email/core.rb', line 17

def self.match str
  raise ArgumentError, "Cannot validate a `#{str.class}`. Only `String` can be." unless str.is_a?(String)
  str.match regexp
end

.regexpRegexp

Returns constant to erase in the children.

Returns:

  • (Regexp)

    constant to erase in the children



23
24
25
26
# File 'lib/ruby_email/core.rb', line 23

def self.regexp
  self::REGEXP
  #raise NoMethodError, "Not implemented in #{self.class}"
end

.validates?(str) ⇒ TrueClass or FalseClass

Check if the String is a valid email.

Parameters:

Returns:

  • (TrueClass or FalseClass)

Raises:

  • (ArgumentError)

    if str is not a String



9
10
11
# File 'lib/ruby_email/core.rb', line 9

def self.validates? str
  !!match(str)
end