Class: Peoplefinder::EmailAddress

Inherits:
Mail::Address
  • Object
show all
Defined in:
app/models/peoplefinder/email_address.rb

Constant Summary collapse

VALID_EMAIL_PATTERN =
/\A[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+\z/

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ EmailAddress

Returns a new instance of EmailAddress.



6
7
8
9
# File 'app/models/peoplefinder/email_address.rb', line 6

def initialize(string)
  return false unless string =~ VALID_EMAIL_PATTERN
  super
end

Instance Method Details

#inferred_first_nameObject



31
32
33
# File 'app/models/peoplefinder/email_address.rb', line 31

def inferred_first_name
  local.split('.')[0] if multipart_local?
end

#inferred_last_nameObject



23
24
25
26
27
28
29
# File 'app/models/peoplefinder/email_address.rb', line 23

def inferred_last_name
  if multipart_local?
    local.split('.')[1]
  else
    local.split('.')[0]
  end
end

#multipart_local?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/models/peoplefinder/email_address.rb', line 35

def multipart_local?
  local.split('.').length > 1
end

#valid_address?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'app/models/peoplefinder/email_address.rb', line 19

def valid_address?
  address ? (valid_format? && valid_domain?) : false
end

#valid_domain?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'app/models/peoplefinder/email_address.rb', line 11

def valid_domain?
  .include?(domain)
end

#valid_format?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'app/models/peoplefinder/email_address.rb', line 15

def valid_format?
  address && address.match(VALID_EMAIL_PATTERN)
end