Class: Mail::PartsList
- Inherits:
-
Array
- Object
- Array
- Mail::PartsList
- Defined in:
- lib/mail/parts_list.rb
Instance Attribute Summary collapse
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
Instance Method Summary collapse
- #attachments ⇒ Object
- #collect ⇒ Object (also: #map)
- #collect! ⇒ Object
- #delete_attachments ⇒ Object
-
#encode_with(coder) ⇒ Object
The #encode_with and #to_yaml methods are just implemented for the sake of backward compatibility ; the delegator does not correctly delegate these calls to the delegated object.
-
#initialize(*args) ⇒ PartsList
constructor
A new instance of PartsList.
- #inspect_structure(parent_id = '') ⇒ Object
- #map! ⇒ Object
- #recursive_delete_if ⇒ Object
- #recursive_each(&block) ⇒ Object
- #recursive_size ⇒ Object
- #sort ⇒ Object
- #sort!(order) ⇒ Object
-
#to_yaml(options = {}) ⇒ Object
:nodoc:.
Constructor Details
#initialize(*args) ⇒ PartsList
Returns a new instance of PartsList.
8 9 10 11 |
# File 'lib/mail/parts_list.rb', line 8 def initialize(*args) @parts = Array.new(*args) super @parts end |
Instance Attribute Details
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
6 7 8 |
# File 'lib/mail/parts_list.rb', line 6 def parts @parts end |
Instance Method Details
#attachments ⇒ Object
24 25 26 |
# File 'lib/mail/parts_list.rb', line 24 def Mail::AttachmentsList.new(@parts) end |
#collect ⇒ Object Also known as: map
28 29 30 31 32 33 34 35 36 |
# File 'lib/mail/parts_list.rb', line 28 def collect if block_given? ary = PartsList.new each { |o| ary << yield(o) } ary else to_a end end |
#collect! ⇒ Object
43 44 45 |
# File 'lib/mail/parts_list.rb', line 43 def collect! raise NoMethodError, "#collect! is not defined, please call #collect and create a new PartsList" end |
#delete_attachments ⇒ Object
98 99 100 101 102 |
# File 'lib/mail/parts_list.rb', line 98 def recursive_delete_if { |part| part. } end |
#encode_with(coder) ⇒ Object
The #encode_with and #to_yaml methods are just implemented for the sake of backward compatibility ; the delegator does not correctly delegate these calls to the delegated object
16 17 18 |
# File 'lib/mail/parts_list.rb', line 16 def encode_with(coder) # :nodoc: coder.represent_object(nil, @parts) end |
#inspect_structure(parent_id = '') ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/mail/parts_list.rb', line 47 def inspect_structure(parent_id = '') enum_for(:map).with_index { |part, i| i = i + 1 # Use 1-based indexes since this is for humans to read id = parent_id.empty? ? "#{i}" : "#{parent_id}.#{i}" if part.content_type == "message/rfc822" sub_list = Mail.new(part.body).parts else sub_list = part.parts end id + '. ' + part.inspect + if sub_list.any? "\n" + sub_list.inspect_structure(id) end.to_s }.join("\n") end |
#map! ⇒ Object
39 40 41 |
# File 'lib/mail/parts_list.rb', line 39 def map! raise NoMethodError, "#map! is not defined, please call #collect and create a new PartsList" end |
#recursive_delete_if ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/mail/parts_list.rb', line 83 def recursive_delete_if delete_if { |part| if part.content_type == "message/rfc822" sub_list = Mail.new(part.body).parts else sub_list = part.parts end (yield part).tap { if sub_list.any? sub_list.recursive_delete_if {|part| yield part } end } } end |
#recursive_each(&block) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/mail/parts_list.rb', line 63 def recursive_each(&block) each do |part| if part.content_type == "message/rfc822" sub_list = Mail.new(part.body).parts else sub_list = part.parts end yield part sub_list.recursive_each(&block) end end |
#recursive_size ⇒ Object
77 78 79 80 81 |
# File 'lib/mail/parts_list.rb', line 77 def recursive_size i = 0 recursive_each {|p| i += 1 } i end |
#sort ⇒ Object
104 105 106 |
# File 'lib/mail/parts_list.rb', line 104 def sort self.class.new(@parts.sort) end |
#sort!(order) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/mail/parts_list.rb', line 108 def sort!(order) # stable sort should be used to maintain the relative order as the parts are added i = 0; sorted = @parts.sort_by do |a| # OK, 10000 is arbitrary... if anyone actually wants to explicitly sort 10000 parts of a # single email message... please show me a use case and I'll put more work into this method, # in the meantime, it works :) get_order_value(a, order) << (i += 1) end @parts.clear sorted.each { |p| @parts << p } end |
#to_yaml(options = {}) ⇒ Object
:nodoc:
20 21 22 |
# File 'lib/mail/parts_list.rb', line 20 def to_yaml( = {}) # :nodoc: @parts.to_yaml() end |