Class: MultipartBody
- Inherits:
-
Object
- Object
- MultipartBody
- Defined in:
- lib/multipart_body/multipart_body.rb
Instance Attribute Summary collapse
-
#boundary ⇒ Object
Returns the value of attribute boundary.
-
#parts ⇒ Object
Returns the value of attribute parts.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(parts = nil, boundary = nil) ⇒ MultipartBody
constructor
A new instance of MultipartBody.
- #to_s ⇒ Object
Constructor Details
#initialize(parts = nil, boundary = nil) ⇒ MultipartBody
Returns a new instance of MultipartBody.
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/multipart_body/multipart_body.rb', line 4 def initialize(parts = nil, boundary = nil) @parts = [] @boundary = boundary || "----multipart-boundary-#{rand(1000000)}" if parts.is_a? Hash @parts = parts.map {|name, body| Part.new(:name => name, :body => body) } elsif parts.is_a?(Array) && parts.first.is_a?(Part) @parts = parts end self end |
Instance Attribute Details
#boundary ⇒ Object
Returns the value of attribute boundary.
2 3 4 |
# File 'lib/multipart_body/multipart_body.rb', line 2 def boundary @boundary end |
#parts ⇒ Object
Returns the value of attribute parts.
2 3 4 |
# File 'lib/multipart_body/multipart_body.rb', line 2 def parts @parts end |
Class Method Details
.from_hash(parts_hash) ⇒ Object
17 18 19 |
# File 'lib/multipart_body/multipart_body.rb', line 17 def self.from_hash(parts_hash) multipart = self.new(parts_hash) end |
Instance Method Details
#to_s ⇒ Object
21 22 23 24 25 |
# File 'lib/multipart_body/multipart_body.rb', line 21 def to_s output = "--#{@boundary}\r\n" output << @parts.join("\r\n--#{@boundary}\r\n") output << "\r\n--#{@boundary}--" end |