Class: Landline::Util::FormPart

Inherits:
Struct
  • Object
show all
Defined in:
lib/landline/util/multipart.rb,
lib/landline/util/multipart.rb

Overview

Valid element of form data with headers

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dataObject

Data received in the field through form data



21
22
23
# File 'lib/landline/util/multipart.rb', line 21

def data
  @data
end

#filenameObject

Original name of the sent file



21
22
23
# File 'lib/landline/util/multipart.rb', line 21

def filename
  @filename
end

#filetypeObject

MIME-type of the file



21
22
23
# File 'lib/landline/util/multipart.rb', line 21

def filetype
  @filetype
end

#headersObject

Returns the value of attribute headers

Returns:

  • (Object)

    the current value of headers



12
13
14
# File 'lib/landline/util/multipart.rb', line 12

def headers
  @headers
end

#nameObject

name of the form part



21
22
23
# File 'lib/landline/util/multipart.rb', line 21

def name
  @name
end

#tempfileObject

Returns the value of attribute tempfile

Returns:

  • (Object)

    the current value of tempfile



12
13
14
# File 'lib/landline/util/multipart.rb', line 12

def tempfile
  @tempfile
end

Instance Method Details

#decode(data) ⇒ Object

Decode charset parameter



29
30
31
32
33
34
# File 'lib/landline/util/multipart.rb', line 29

def decode(data)
  data = Landline::Util.unescape_html(data)
  return data.force_encoding("UTF-8") unless self.headers['charset']

  data.force_encoding(self.headers['charset']).encode("UTF-8")
end

#file?Boolean

Is this form part a file or plain data?

Returns:

  • (Boolean)


24
25
26
# File 'lib/landline/util/multipart.rb', line 24

def file?
  !tempfile.nil?
end

#simplifyFormPart, String

If FormPart is not a file, simplify to string.

Returns:



38
39
40
# File 'lib/landline/util/multipart.rb', line 38

def simplify
  file? ? self : decode(self.data)
end