Class: InternetMessage::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/internet_message/address.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(local_part, domain) ⇒ Address

Returns a new instance of Address.

Parameters:

  • local_part (String)

    local part of mail address

  • domain (String)

    domain part of mail 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

#domainObject (readonly)

Returns the value of attribute domain.



4
5
6
# File 'lib/internet_message/address.rb', line 4

def domain
  @domain
end

#local_partObject (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.

Parameters:

Returns:

  • (true, false)


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_sString

Returns mail address.

Returns:

  • (String)

    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