Module: RubyEmail

Defined in:
lib/ruby_email/core.rb,
lib/ruby_email/public.rb

Overview

Defined Under Namespace

Modules: Public, String

Constant Summary collapse

ATEXT =

one valid character (not . because used to separe domains)

'([A-Za-z0-9!#\$%&\'*\+\-/=\?\^_`\{\}\|~])'
ATOM =
"#{ATEXT}+"
DOT_ATOM_TEXT =
"(#{ATOM})(\\.#{ATOM})*"
VALIDE =

email grammar

"(?<local>#{DOT_ATOM_TEXT})@(?<domain>#{DOT_ATOM_TEXT})"
REGEXP =

regexp to validate complete email

Regexp.new "\\A#{VALIDE}\\Z"

Class Method Summary collapse

Class Method Details

.match(str) ⇒ MatchData or NilClass

Check if the string is a valid email and details how

Parameters:

  • string to match

Returns:

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

Raises:

  • if str is not a String



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

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

.validates?(str) ⇒ TrueClass or FalseClass

Check if the String is a valid email

Parameters:

  • string to match

Returns:

Raises:

  • if str is not a String



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

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