Class: File

Inherits:
Object
  • Object
show all
Defined in:
lib/rdig/file.rb

Overview

Extend class File with a content_type method

Constant Summary collapse

FILE_EXTENSION_MIME_TYPES =

mime types and file extensions

{
  'doc'  => 'application/msword',
  'html' => 'text/html',
  'htm'  => 'text/html',
  #'.odt'  => 'application/vnd.oasis.opendocument.text',
  'pdf'  => 'application/pdf',
  'txt'  => 'text/plain',
}

Instance Method Summary collapse

Instance Method Details

#content_typeObject



14
15
16
# File 'lib/rdig/file.rb', line 14

def content_type
  FILE_EXTENSION_MIME_TYPES[File.extname(self.path).downcase.gsub(/^\./,'')] || 'application/octet-stream'
end