Class: FileParam

Inherits:
Object
  • Object
show all
Defined in:
lib/captured/uploaders/imageshack_uploader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contentObject

Returns the value of attribute content.



110
111
112
# File 'lib/captured/uploaders/imageshack_uploader.rb', line 110

def content
  @content
end

#filenameObject

Returns the value of attribute filename.



110
111
112
# File 'lib/captured/uploaders/imageshack_uploader.rb', line 110

def filename
  @filename
end

#kObject

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_multipartObject



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