Class: Multipart::Post::Parts::ParamPart

Inherits:
Object
  • Object
show all
Includes:
Part
Defined in:
lib/multipart/post/parts.rb

Overview

Represents a parametric part to be filled with given value.

Instance Method Summary collapse

Methods included from Part

file?, new, #to_io

Constructor Details

#initialize(boundary, name, value, headers = {}) ⇒ ParamPart

Returns a new instance of ParamPart.

Parameters:

  • boundary (String)
  • name (#to_s)
  • value (String)
  • headers (Hash) (defaults to: {})

    Content-Type and Content-ID are used, if present.



58
59
60
61
# File 'lib/multipart/post/parts.rb', line 58

def initialize(boundary, name, value, headers = {})
  @part = build_part(boundary, name, value, headers)
  @io = StringIO.new(@part)
end

Instance Method Details

#build_part(boundary, name, value, headers = {}) ⇒ Object

Parameters:

  • boundary (String)
  • name (#to_s)
  • value (String)
  • headers (Hash) (defaults to: {})

    Content-Type is used, if present.



71
72
73
74
75
76
77
78
79
# File 'lib/multipart/post/parts.rb', line 71

def build_part(boundary, name, value, headers = {})
  part = String.new
  part << "--#{boundary}\r\n"
  part << "Content-ID: #{headers["Content-ID"]}\r\n" if headers["Content-ID"]
  part << "Content-Disposition: form-data; name=\"#{name.to_s}\"\r\n"
  part << "Content-Type: #{headers["Content-Type"]}\r\n" if headers["Content-Type"]
  part << "\r\n"
  part << "#{value}\r\n"
end

#lengthObject



63
64
65
# File 'lib/multipart/post/parts.rb', line 63

def length
  @part.bytesize
end