Module: RubyEmail::Public

Defined in:
lib/ruby_email/public.rb

Overview

Only valid on the public internet. “toto@toto” is not valid, but “[email protected]” is good

Defined Under Namespace

Modules: 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 =
"(?<local>#{DOT_ATOM_TEXT})@(?<domain>#{DOT_ATOM_TEXT}\\.#{DOT_ATOM_TEXT})"
REGEXP =
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 on internet and details how

Raises:

  • if str is not a String

Parameters:

  • string to match

Returns:

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



27
28
29
30
# File 'lib/ruby_email/public.rb', line 27

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 on internet

Raises:

  • if str is not a String

Parameters:

  • string to match

Returns:



19
20
21
# File 'lib/ruby_email/public.rb', line 19

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