Class: FileParam
- Inherits:
-
Object
- Object
- FileParam
- Defined in:
- lib/captured/uploaders/imageshack_uploader.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#k ⇒ Object
Returns the value of attribute k.
Instance Method Summary collapse
-
#initialize(k, filename, content) ⇒ FileParam
constructor
A new instance of FileParam.
- #to_multipart ⇒ Object
- #type_for(filename) ⇒ Object
Constructor Details
#initialize(k, filename, content) ⇒ FileParam
Returns a new instance of FileParam.
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/captured/uploaders/imageshack_uploader.rb', line 112 def initialize(k, filename, content) @k = k @filename = filename @content = content @extension_index = { 'jpg' => "image/jpeg", 'jpeg' => "image/jpeg", 'png' => "image/png", 'bmp' => "image/bmpimage/x-bmp", 'tiff' => "image/tiff", 'tif' => "image/tiff"} end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
110 111 112 |
# File 'lib/captured/uploaders/imageshack_uploader.rb', line 110 def content @content end |
#filename ⇒ Object
Returns the value of attribute filename.
110 111 112 |
# File 'lib/captured/uploaders/imageshack_uploader.rb', line 110 def filename @filename end |
#k ⇒ Object
Returns the value of attribute k.
110 111 112 |
# File 'lib/captured/uploaders/imageshack_uploader.rb', line 110 def k @k end |
Instance Method Details
#to_multipart ⇒ Object
131 132 133 134 |
# File 'lib/captured/uploaders/imageshack_uploader.rb', line 131 def to_multipart return "Content-Disposition: form-data; name=\"#{CGI::escape(k)}\"; filename=\"#{filename}\"\r\n" + "Content-Type: #{type_for(@filename)}\r\n\r\n" + content + "\r\n" end |
#type_for(filename) ⇒ Object
125 126 127 128 |
# File 'lib/captured/uploaders/imageshack_uploader.rb', line 125 def type_for(filename) ext = filename.chomp.downcase.gsub(/.*\./o, '') @extension_index[ext] end |