Class: InternetMessage::Address
- Inherits:
-
Object
- Object
- InternetMessage::Address
- Defined in:
- lib/internet_message/address.rb
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#local_part ⇒ Object
readonly
Returns the value of attribute local_part.
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Compare self to other.
-
#initialize(local_part, domain) ⇒ Address
constructor
A new instance of Address.
- #quote_string(s) ⇒ Object
-
#to_s ⇒ String
Mail address.
Constructor Details
#initialize(local_part, domain) ⇒ Address
Returns a new instance of Address.
8 9 10 |
# File 'lib/internet_message/address.rb', line 8 def initialize(local_part, domain) @local_part, @domain = local_part, domain end |
Instance Attribute Details
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
4 5 6 |
# File 'lib/internet_message/address.rb', line 4 def domain @domain end |
#local_part ⇒ Object (readonly)
Returns the value of attribute local_part.
4 5 6 |
# File 'lib/internet_message/address.rb', line 4 def local_part @local_part end |
Instance Method Details
#==(other) ⇒ true, false
Compare self to other. local_part and domain are case insensitive.
30 31 32 |
# File 'lib/internet_message/address.rb', line 30 def ==(other) other.is_a?(Address) && other.local_part.downcase == self.local_part.downcase && other.domain.downcase == self.domain.downcase end |
#quote_string(s) ⇒ Object
23 24 25 |
# File 'lib/internet_message/address.rb', line 23 def quote_string(s) '"'+s.gsub(/[\\\"]/){"\\#{$&}"}+'"' end |
#to_s ⇒ String
Returns mail address.
13 14 15 16 17 18 19 20 |
# File 'lib/internet_message/address.rb', line 13 def to_s if @local_part =~ /\A[0-9a-zA-Z\!\#\$\%\'\*\+\-\/\=\?\^\_\`\{\|\}\~]+(\.[0-9a-zA-Z\!\#\$\%\'\*\+\-\/\=\?\^\_\`\{\|\}\~]+)*\z/n l = @local_part else l = quote_string(@local_part) end "#{l}@#{@domain}" end |