Module: Ramaze::Tool::MIME

Defined in:
lib/ramaze/tool/mime.rb

Overview

Responsible for lookup of MIME info for filetypes based on extension.

Class Method Summary collapse

Class Method Details

.ext_for(mime) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/ramaze/tool/mime.rb', line 23

def ext_for(mime)
  exts = []

  trait[:types].each do |ext, mime_type|
    exts << ext if mime == mime_type
  end

  exts.sort_by{|e| e.size }.first
end

.type_for(file) ⇒ Object

Get MIME-type for the given filename based on extension. Answers with an empty string if none is found.



18
19
20
21
# File 'lib/ramaze/tool/mime.rb', line 18

def type_for(file)
  ext = File.extname(file)
  trait[:types][ext].to_s
end