Class: MimeNew

Inherits:
Object
  • Object
show all
Defined in:
lib/helpers/mime_types_new.rb

Overview

This class will include the Office 2007 extension types when looking up MIME types.

Constant Summary collapse

DefaultUnknownContentType =
"application/octet-stream"

Class Method Summary collapse

Class Method Details

.for_ofc_x(fname) ⇒ Object

Returns the mime type of a file

MimeNew.for_ofc_x('a_new_word_doc.docx') 
#=>  "application/vnd.openxmlformats-officedocument.wordprocessingml.document"


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/helpers/mime_types_new.rb', line 15

def self.for_ofc_x(fname)
  cont_type = nil
  old_ext = File.extname(fname)
  cont_type =case old_ext
    #New Office Formats
  when '.docx'
    ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"]
  when '.dotx'
    ["application/vnd.openxmlformats-officedocument.wordprocessingml.template"]
  when '.pptx'
    ["application/vnd.openxmlformats-officedocument.presentationml.presentation"]
  when '.ppsx'
    ["application/vnd.openxmlformats-officedocument.presentationml.slideshow"]
  when '.potx'
    ["application/vnd.openxmlformats-officedocument.presentationml.template"]
  when '.xlsx'
    ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"]
  when '.xltx'
    ["application/vnd.openxmlformats-officedocument.spreadsheetml.template"]
  else
    self.other_content_types(fname)
  end#case
  cont_type = [cont_type].flatten.first
  #puts "Content Type returned: #{cont_type.inspect}"
  return cont_type
end

.just_ofc_x(ext) ⇒ Object

def



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/helpers/mime_types_new.rb', line 42

def self.just_ofc_x(ext)
  cont_type = case File.extname(fname)
    #New Office Formats
  when '.docx'
    ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"]
  when '.dotx'
    ["application/vnd.openxmlformats-officedocument.wordprocessingml.template"]
  when '.pptx'
    ["application/vnd.openxmlformats-officedocument.presentationml.presentation"]
  when '.ppsx'
    ["application/vnd.openxmlformats-officedocument.presentationml.slideshow"]
  when '.potx'
    ["application/vnd.openxmlformats-officedocument.presentationml.template"]
  when '.xlsx'
    ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"]
  when '.xltx'
    ["application/vnd.openxmlformats-officedocument.spreadsheetml.template"]
  end
end

.other_content_types(fname) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/helpers/mime_types_new.rb', line 62

def self.other_content_types(fname)
  std_type = MIME::Types.type_for(fname).first
  rtn = if std_type
    std_type.content_type
  else
    DefaultUnknownContentType
  end
  return rtn
end