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.
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
#address ⇒ String
Return the real mail address:
"Me <[email protected]>" -> "[email protected]"
"[email protected]" -> "[email protected]"
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 |
#name ⇒ String
Extract the ‘name’ out of an mail address:
"Me <[email protected]>" -> "Me"
"[email protected]" -> "me2"
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_s ⇒ Object
37 |
# File 'lib/wcc/mail.rb', line 37 def to_s; @email end |