Class: WCC::MailAddress

Inherits:
Object
  • Object
show all
Defined in:
lib/wcc/mail.rb

Overview

An email address container with internal conversion routines.

Instance Method Summary collapse

Constructor Details

#initialize(email) ⇒ MailAddress

Returns a new instance of MailAddress.



7
8
9
10
# File 'lib/wcc/mail.rb', line 7

def initialize(email)
	email = email.to_s if email.is_a?(MailAddress)
	@email = email.strip
end

Instance Method Details

#addressString

Return the real mail address

"Me <[email protected]>" -> "[email protected]"
"[email protected]" -> "[email protected]"

Returns:



30
31
32
33
34
35
36
# File 'lib/wcc/mail.rb', line 30

def address
	if @email =~ /^[\w\s]+<.+@[^@]+>$/
		@email.match(/<([^>]+@[^@>]+)>/)[1]
	else
		@email
	end
end

#nameString

Extract the ‘name’ out of an mail address

"Me <[email protected]>" -> "Me"
"[email protected]" -> "me2"

Returns:



17
18
19
20
21
22
23
# File 'lib/wcc/mail.rb', line 17

def name
	if @email =~ /^[\w\s]+<.+@[^@]+>$/
		@email.gsub(/<.+?>/, '').strip
	else
		@email.split("@")[0...-1].join("@")
	end
end

#to_sObject



38
# File 'lib/wcc/mail.rb', line 38

def to_s; @email end