Module: Syntropy::MimeTypes
- Defined in:
- lib/syntropy/mime_types.rb
Overview
The MimeTypes module maps file extensions to MIME types.
Constant Summary collapse
- TYPES =
{ 'html' => 'text/html', 'css' => 'text/css', 'js' => 'application/javascript', 'txt' => 'text/plain', 'text' => 'text/plain', 'gif' => 'image/gif', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'png' => 'image/png', 'ico' => 'image/x-icon', 'svg' => 'image/svg+xml', 'pdf' => 'application/pdf', 'json' => 'application/json', }.freeze
- EXT_REGEXP =
/\.?([^\.]+)$/.freeze
Class Method Summary collapse
-
.[](ext) ⇒ String?
Returns the mime type for the given file extension.
Class Method Details
.[](ext) ⇒ String?
Returns the mime type for the given file extension.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/syntropy/mime_types.rb', line 28 def self.[](ext) case ext when Symbol TYPES[ext.to_s] when EXT_REGEXP TYPES[Regexp.last_match(1)] when '' nil else raise "Invalid argument #{ext.inspect}" end end |