Class: Web::Mime

Inherits:
Object show all
Defined in:
lib/web/mime.rb

Overview

Purpose

This class returns mime types. It parses an apache-style mime.types file located in site_lib/web/resources/mime.types for it’s database.

This class can be independantly of the rest of NARF:

require 'web/mime.rb'
Web::Mime::get_mime_type( 'filename.txt' )

Defined Under Namespace

Classes: ApacheUnixReader

Constant Summary collapse

DEFAULT_MIMETYPE =
"text/html"
@@readers =
[]
@@mime_types =
nil

Class Method Summary collapse

Class Method Details

.clearObject



57
58
59
# File 'lib/web/mime.rb', line 57

def clear
  @@mime_types = nil
end

.get_mime_type(filename) ⇒ Object Also known as: get_mimetype



73
74
75
# File 'lib/web/mime.rb', line 73

def get_mime_type( filename )
  mime_types[filename.split(".").last].to_s
end

.mime_typesObject



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/web/mime.rb', line 61

def mime_types
  unless(@@mime_types)
    readers.each{ |klass|
      if klass.applies?
        @@mime_types = klass.new.mime_types
        break
      end
    }
  end
  @@mime_types
end

.readersObject



14
15
16
# File 'lib/web/mime.rb', line 14

def Mime.readers
  @@readers
end