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.



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

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:



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

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:



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

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

#to_sObject



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

def to_s; @email end