Class: HTTP::FormData::Part

Inherits:
Object
  • Object
show all
Defined in:
lib/http/form_data/part.rb

Overview

Represents a body part of multipart/form-data request.

Examples:

Usage with String


body = "Message"
FormData::Part.new body, :content_type => 'foobar.txt; charset="UTF-8"'

Direct Known Subclasses

File

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, opts = {}) ⇒ Part

Returns a new instance of Part.

Parameters:

  • body (#to_s)
  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :content_type (String)

    Value of Content-Type header

  • :filename (String)

    Value of filename parameter



18
19
20
21
22
# File 'lib/http/form_data/part.rb', line 18

def initialize(body, opts = {})
  @body = body.to_s
  @content_type = opts[:content_type]
  @filename = opts[:filename]
end

Instance Attribute Details

#content_typeObject (readonly)

Returns the value of attribute content_type.



12
13
14
# File 'lib/http/form_data/part.rb', line 12

def content_type
  @content_type
end

#filenameObject (readonly)

Returns the value of attribute filename.



12
13
14
# File 'lib/http/form_data/part.rb', line 12

def filename
  @filename
end

Instance Method Details

#sizeInteger

Returns content size.

Returns:

  • (Integer)


27
28
29
# File 'lib/http/form_data/part.rb', line 27

def size
  @body.bytesize
end

#to_sString

Returns content of a file of IO.

Returns:

  • (String)


34
35
36
# File 'lib/http/form_data/part.rb', line 34

def to_s
  @body
end