Class: Parts::ParamPart

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

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.



33
34
35
36
# File 'lib/parts.rb', line 33

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



42
43
44
45
46
47
48
49
# File 'lib/parts.rb', line 42

def build_part(boundary, name, value, headers = {})
  part = ''
  part << "--#{boundary}\r\n"
  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



38
39
40
# File 'lib/parts.rb', line 38

def length
 @part.bytesize
end