Module: Nuggets::ContentType
Instance Method Summary collapse
-
#of(path) ⇒ Object
call-seq: ContentType.of(path) => aString or
nil
.
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.
73 74 75 76 77 |
# File 'lib/nuggets/content_type.rb', line 73 def of(path) ::File.content_type(path) || ::URI.content_type(path) || ( t = ::MIME::Types.of(path).first and t.content_type ) end |