Module: Mail::CommonAddress

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#<<(val) ⇒ Object


90
91
92
93
94
95
96
97
98
99
# File 'lib/mail/fields/common/common_address.rb', line 90

def <<(val)
  case
  when val.nil?
    raise ArgumentError, "Need to pass an address to <<"
  when Utilities.blank?(val)
    parse(encoded)
  else
    self.value = [self.value, val].reject {|a| Utilities.blank?(a) }.join(", ")
  end
end

#addressesObject

Returns the address string of all the addresses in the address list


38
39
40
41
# File 'lib/mail/fields/common/common_address.rb', line 38

def addresses
  list = address_list.addresses.map { |a| a.address }
  Mail::AddressContainer.new(self, list)
end

#addrsObject

Returns the actual address objects in the address list


56
57
58
59
# File 'lib/mail/fields/common/common_address.rb', line 56

def addrs
  list = address_list.addresses
  Mail::AddressContainer.new(self, list)
end

#charsetObject


15
16
17
# File 'lib/mail/fields/common/common_address.rb', line 15

def charset
  @charset
end

#decoded_group_addressesObject

Returns a list of decoded group addresses


72
73
74
# File 'lib/mail/fields/common/common_address.rb', line 72

def decoded_group_addresses
  groups.map { |k,v| v.map { |a| a.decoded } }.flatten
end

#defaultObject


86
87
88
# File 'lib/mail/fields/common/common_address.rb', line 86

def default
  addresses
end

#display_namesObject

Returns the display name of all the addresses in the address list


50
51
52
53
# File 'lib/mail/fields/common/common_address.rb', line 50

def display_names
  list = address_list.addresses.map { |a| a.display_name }
  Mail::AddressContainer.new(self, list)
end

#eachObject

Allows you to iterate through each address object in the address_list


31
32
33
34
35
# File 'lib/mail/fields/common/common_address.rb', line 31

def each
  address_list.addresses.each do |address|
    yield(address)
  end
end

#encode_if_needed(val) ⇒ Object

:nodoc:


19
20
21
22
23
24
25
26
27
28
# File 'lib/mail/fields/common/common_address.rb', line 19

def encode_if_needed(val) #:nodoc:
  # Need to join arrays of addresses into a single value
  if val.kind_of?(Array)
    val.compact.map { |a| encode_if_needed a }.join(', ')

  # Pass through UTF-8; encode non-UTF-8.
  else
    utf8_if_needed(val) || Encodings.encode_non_usascii(val, charset)
  end
end

#encoded_group_addressesObject

Returns a list of encoded group addresses


77
78
79
# File 'lib/mail/fields/common/common_address.rb', line 77

def encoded_group_addresses
  groups.map { |k,v| v.map { |a| a.encoded } }.flatten
end

#formattedObject

Returns the formatted string of all the addresses in the address list


44
45
46
47
# File 'lib/mail/fields/common/common_address.rb', line 44

def formatted
  list = address_list.addresses.map { |a| a.format }
  Mail::AddressContainer.new(self, list)
end

#group_addressesObject

Returns the addresses that are part of groups


67
68
69
# File 'lib/mail/fields/common/common_address.rb', line 67

def group_addresses
  decoded_group_addresses
end

#group_namesObject

Returns the name of all the groups in a string


82
83
84
# File 'lib/mail/fields/common/common_address.rb', line 82

def group_names # :nodoc:
  address_list.group_names
end

#groupsObject

Returns a hash of group name => address strings for the address list


62
63
64
# File 'lib/mail/fields/common/common_address.rb', line 62

def groups
  address_list.addresses_grouped_by_group
end

#parse(val = value) ⇒ Object


7
8
9
10
11
12
13
# File 'lib/mail/fields/common/common_address.rb', line 7

def parse(val = value)
  unless Utilities.blank?(val)
    @address_list = AddressList.new(encode_if_needed(val))
  else
    nil
  end
end

#value=(val) ⇒ Object


101
102
103
104
# File 'lib/mail/fields/common/common_address.rb', line 101

def value=(val)
  super
  parse(self.value)
end