Class: As2::MimeGenerator::Part
- Inherits:
-
Object
- Object
- As2::MimeGenerator::Part
- Defined in:
- lib/as2/mime_generator.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #add_part(part) ⇒ Object
- #body ⇒ Object
- #body=(body) ⇒ Object
-
#initialize ⇒ Part
constructor
A new instance of Part.
- #multipart? ⇒ Boolean
- #write(io) ⇒ Object
Constructor Details
#initialize ⇒ Part
Returns a new instance of Part.
4 5 6 7 8 9 |
# File 'lib/as2/mime_generator.rb', line 4 def initialize @parts = [] @body = "" @headers = {} @id = nil end |
Instance Method Details
#[](name) ⇒ Object
11 12 13 |
# File 'lib/as2/mime_generator.rb', line 11 def [](name) @headers[name] end |
#[]=(name, value) ⇒ Object
15 16 17 |
# File 'lib/as2/mime_generator.rb', line 15 def []=(name, value) @headers[name] = value end |
#add_part(part) ⇒ Object
30 31 32 33 34 |
# File 'lib/as2/mime_generator.rb', line 30 def add_part(part) gen_id unless @id @parts << part @body = nil end |
#body ⇒ Object
19 20 21 |
# File 'lib/as2/mime_generator.rb', line 19 def body @body end |
#body=(body) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/as2/mime_generator.rb', line 23 def body=(body) unless @parts.empty? raise "Cannot add plain budy to multipart" end @body = body end |
#multipart? ⇒ Boolean
36 37 38 |
# File 'lib/as2/mime_generator.rb', line 36 def multipart? ! @parts.empty? end |
#write(io) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/as2/mime_generator.rb', line 40 def write(io) @headers.each do |name, value| if multipart? && name =~ /content-type/i io.print "#{name}: #{value}; \r\n" io.print "\tboundary=\"----=_Part_#{@id}\"\r\n" else io.print "#{name}: #{value}\r\n" end end io.print "\r\n" if @parts.empty? io.print @body, "\r\n" else @parts.each do|p| io.print "------=_Part_#{@id}\r\n" p.write(io) end io.print "------=_Part_#{@id}--\r\n" end io.print "\r\n" end |