Class: WCC::MailAddress
- Inherits:
-
Object
- Object
- WCC::MailAddress
- Defined in:
- lib/wcc/mail.rb
Overview
An email address container with internal conversion routines.
Instance Method Summary collapse
-
#address ⇒ String
Return the real mail address “Me <[email protected]>” -> “[email protected]” “[email protected]” -> “[email protected]”.
-
#initialize(email) ⇒ MailAddress
constructor
A new instance of MailAddress.
-
#name ⇒ String
Extract the ‘name’ out of an mail address “Me <[email protected]>” -> “Me” “[email protected]” -> “me2”.
- #to_s ⇒ Object
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
#address ⇒ String
Return the real mail address
"Me <[email protected]>" -> "[email protected]"
"[email protected]" -> "[email protected]"
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 |
#name ⇒ String
Extract the ‘name’ out of an mail address
"Me <[email protected]>" -> "Me"
"[email protected]" -> "me2"
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_s ⇒ Object
38 |
# File 'lib/wcc/mail.rb', line 38 def to_s; @email end |