Class: Mail::CommonAddressField
- Inherits:
-
NamedStructuredField
- Object
- CommonField
- StructuredField
- NamedStructuredField
- Mail::CommonAddressField
- Defined in:
- lib/mail/fields/common_address_field.rb
Overview
:nodoc:
Direct Known Subclasses
BccField, CcField, FromField, ReplyToField, ResentBccField, ResentCcField, ResentFromField, ResentSenderField, ResentToField, ReturnPathField, SenderField, ToField
Instance Attribute Summary
Attributes inherited from CommonField
#charset, #errors, #name, #value
Class Method Summary collapse
Instance Method Summary collapse
- #<<(val) ⇒ Object
- #address ⇒ Object
-
#addresses ⇒ Object
Returns the address string of all the addresses in the address list.
-
#addrs ⇒ Object
Returns the actual address objects in the address list.
-
#decoded_group_addresses ⇒ Object
Returns a list of decoded group addresses.
- #default ⇒ Object
-
#display_names ⇒ Object
Returns the display name of all the addresses in the address list.
-
#each ⇒ Object
Allows you to iterate through each address object in the address_list.
-
#element ⇒ Object
:nodoc:.
-
#encode_if_needed(val, val_charset = charset) ⇒ Object
:nodoc:.
-
#encoded_group_addresses ⇒ Object
Returns a list of encoded group addresses.
-
#formatted ⇒ Object
Returns the formatted string of all the addresses in the address list.
-
#group_addresses ⇒ Object
Returns the addresses that are part of groups.
-
#group_names ⇒ Object
Returns the name of all the groups in a string.
-
#groups ⇒ Object
Returns a hash of group name => address strings for the address list.
-
#initialize(value = nil, charset = nil) ⇒ CommonAddressField
constructor
A new instance of CommonAddressField.
Methods inherited from CommonField
#decoded, #encoded, #parse, parse, #responsible_for?, #singular?, #to_s
Constructor Details
#initialize(value = nil, charset = nil) ⇒ CommonAddressField
Returns a new instance of CommonAddressField.
21 22 23 |
# File 'lib/mail/fields/common_address_field.rb', line 21 def initialize(value = nil, charset = nil) super encode_if_needed(value, charset), charset end |
Class Method Details
.singular? ⇒ Boolean
17 18 19 |
# File 'lib/mail/fields/common_address_field.rb', line 17 def self.singular? true end |
Instance Method Details
#<<(val) ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/mail/fields/common_address_field.rb', line 93 def <<(val) case when val.nil? raise ArgumentError, "Need to pass an address to <<" when Utilities.blank?(val) self else self.value = [self.value, encode_if_needed(val)].reject { |a| Utilities.blank?(a) }.join(", ") end end |
#address ⇒ Object
40 41 42 |
# File 'lib/mail/fields/common_address_field.rb', line 40 def address addresses.first end |
#addresses ⇒ Object
Returns the address string of all the addresses in the address list
45 46 47 48 |
# File 'lib/mail/fields/common_address_field.rb', line 45 def addresses list = element.addresses.map { |a| a.address } Mail::AddressContainer.new(self, list) end |
#addrs ⇒ Object
Returns the actual address objects in the address list
63 64 65 66 |
# File 'lib/mail/fields/common_address_field.rb', line 63 def addrs list = element.addresses Mail::AddressContainer.new(self, list) end |
#decoded_group_addresses ⇒ Object
Returns a list of decoded group addresses
79 80 81 |
# File 'lib/mail/fields/common_address_field.rb', line 79 def decoded_group_addresses groups.map { |k,v| v.map { |a| a.decoded } }.flatten end |
#default ⇒ Object
36 37 38 |
# File 'lib/mail/fields/common_address_field.rb', line 36 def default addresses end |
#display_names ⇒ Object
Returns the display name of all the addresses in the address list
57 58 59 60 |
# File 'lib/mail/fields/common_address_field.rb', line 57 def display_names list = element.addresses.map { |a| a.display_name } Mail::AddressContainer.new(self, list) end |
#each ⇒ Object
Allows you to iterate through each address object in the address_list
30 31 32 33 34 |
# File 'lib/mail/fields/common_address_field.rb', line 30 def each element.addresses.each do |address| yield(address) end end |
#element ⇒ Object
:nodoc:
25 26 27 |
# File 'lib/mail/fields/common_address_field.rb', line 25 def element # :nodoc: @element ||= AddressList.new(value) end |
#encode_if_needed(val, val_charset = charset) ⇒ Object
:nodoc:
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/mail/fields/common_address_field.rb', line 104 def encode_if_needed(val, val_charset = charset) #:nodoc: case val when nil val # Need to join arrays of addresses into a single value when Array val.compact.map { |a| encode_if_needed a, val_charset }.join(', ') # Pass through UTF-8; encode non-UTF-8. else utf8_if_needed(val, val_charset) || Encodings.encode_non_usascii(val, val_charset) end end |
#encoded_group_addresses ⇒ Object
Returns a list of encoded group addresses
84 85 86 |
# File 'lib/mail/fields/common_address_field.rb', line 84 def encoded_group_addresses groups.map { |k,v| v.map { |a| a.encoded } }.flatten end |
#formatted ⇒ Object
Returns the formatted string of all the addresses in the address list
51 52 53 54 |
# File 'lib/mail/fields/common_address_field.rb', line 51 def formatted list = element.addresses.map { |a| a.format } Mail::AddressContainer.new(self, list) end |
#group_addresses ⇒ Object
Returns the addresses that are part of groups
74 75 76 |
# File 'lib/mail/fields/common_address_field.rb', line 74 def group_addresses decoded_group_addresses end |
#group_names ⇒ Object
Returns the name of all the groups in a string
89 90 91 |
# File 'lib/mail/fields/common_address_field.rb', line 89 def group_names # :nodoc: element.group_names end |
#groups ⇒ Object
Returns a hash of group name => address strings for the address list
69 70 71 |
# File 'lib/mail/fields/common_address_field.rb', line 69 def groups element.addresses_grouped_by_group end |