Module: Util::ContentType

Extended by:
ContentType
Included in:
ContentType
Defined in:
lib/nuggets/util/content_type.rb

Instance Method Summary collapse

Instance Method Details

#of(path) ⇒ Object

call-seq:

ContentType.of(path) => aString or nil

Get the MIME-Type of the file living at path. Either by looking directly into the file (requires FileMagic), or, assuming path might denote a URI, by asking the web server (via OpenURI), or finally by just looking at the file extension (requires MIME::Types). Returns nil in case no decision could be made.

NOTE: This is really only useful with the filemagic and mime-types gems installed.



80
81
82
83
84
# File 'lib/nuggets/util/content_type.rb', line 80

def of(path)
  File.content_type(path) || URI.content_type(path) || (
    t = MIME::Types.of(path).first and t.content_type
  )
end