Class: Landline::Util::FormPart
- Inherits:
-
Struct
- Object
- Struct
- Landline::Util::FormPart
- Defined in:
- lib/landline/util/multipart.rb,
lib/landline/util/multipart.rb
Overview
Valid element of form data with headers
Instance Attribute Summary collapse
-
#data ⇒ Object
Data received in the field through form data.
-
#filename ⇒ Object
Original name of the sent file.
-
#filetype ⇒ Object
MIME-type of the file.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#name ⇒ Object
name of the form part.
-
#tempfile ⇒ Object
Returns the value of attribute tempfile.
Instance Method Summary collapse
-
#decode(data) ⇒ Object
Decode charset parameter.
-
#file? ⇒ Boolean
Is this form part a file or plain data?.
-
#simplify ⇒ FormPart, String
If FormPart is not a file, simplify to string.
Instance Attribute Details
#data ⇒ Object
Data received in the field through form data
21 22 23 |
# File 'lib/landline/util/multipart.rb', line 21 def data @data end |
#filename ⇒ Object
Original name of the sent file
21 22 23 |
# File 'lib/landline/util/multipart.rb', line 21 def filename @filename end |
#filetype ⇒ Object
MIME-type of the file
21 22 23 |
# File 'lib/landline/util/multipart.rb', line 21 def filetype @filetype end |
#headers ⇒ Object
Returns the value of attribute headers
12 13 14 |
# File 'lib/landline/util/multipart.rb', line 12 def headers @headers end |
#name ⇒ Object
name of the form part
21 22 23 |
# File 'lib/landline/util/multipart.rb', line 21 def name @name end |
#tempfile ⇒ Object
Returns the value of attribute 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?
24 25 26 |
# File 'lib/landline/util/multipart.rb', line 24 def file? !tempfile.nil? end |
#simplify ⇒ FormPart, String
If FormPart is not a file, simplify to string.
38 39 40 |
# File 'lib/landline/util/multipart.rb', line 38 def simplify file? ? self : decode(self.data) end |