Class: Email

Inherits:
ApplicationRecord
  • Object
show all
Includes:
Labelize
Defined in:
app/models/email.rb

Constant Summary collapse

VALID_EMAIL_FORMAT_REGEX =
/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.canonicalize(addr) ⇒ Object



12
13
14
15
# File 'app/models/email.rb', line 12

def self.canonicalize(addr)
  candidate = addr.strip.downcase if not addr.blank?
  candidate ||= addr
end

.valid_format?(addr) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'app/models/email.rb', line 21

def self.valid_format?(addr)
  return (addr =~ VALID_EMAIL_FORMAT_REGEX) != nil
end

Instance Method Details

#canonicalizeObject



17
18
19
# File 'app/models/email.rb', line 17

def canonicalize
  self.address = self.class.canonicalize(self.address)
end

#default_labelObject



25
26
27
# File 'app/models/email.rb', line 25

def default_label
  self.label = Label.get("Work")
end