Module MIME::Types |
|
MIME types are used in MIME-compliant communications, as in e-mail or HTTP traffic, to indicate the type of content which is transmitted. MIME::Types provides the ability for detailed information about MIME entities (provided as a set of MIME::Type objects) )to be determined and used programmatically. There are many types defined by RFCs and vendors, so the list is long but not complete; don’t hesitate to ask to add additional information. This library follows the IANA collection of MIME types (see below for reference).
MIME types are used in MIME entities, as in email or HTTP traffic. It is useful at times to have information available about MIME types (or, inversely, about files). A MIME::Type stores the known information about one MIME type.
require 'mime/types' plaintext = MIME::Types['text/plain'] print plaintext.media_type # => 'text' print plaintext.sub_type # => 'plain' puts plaintext.extensions.join(" ") # => 'asc txt c cc h hh cpp' puts plaintext.encoding # => 8bit puts plaintext.binary? # => false puts plaintext.ascii? # => true puts plaintext == 'text/plain' # => true puts MIME::Type.simplified('x-appl/x-zip') # => 'appl/zip'
This module is built to conform to the MIME types of RFC’s 2045 and 2231. It follows the official IANA registry at www.iana.org/assignments/media-types/ and the collection kept at www.ltsw.se/knbase/internet/mime.htp
This is originally based on Perl MIME::Types.
Copyright: | Copyright © 2002 - 2004 by Austin Ziegler <mime-types@halostatue.ca> |
Version: | 1.13 |
Based On: | Perl MIME::Types, Copyright © 2001-2004 by Mark Overmeer <mimetypes@overmeer.net>. |
Licence: | Ruby’s, Perl Artistic, or GPL version 2 (or later) |
See Also: | www.iana.org/assignments/media-types/ www.ltsw.se/knbase/internet/mime.htp |
Methods |
Public Class methods |
[](type_id, flags = {}) |
Returns a list of MIME::Type objects, which may be empty. The optional flag parameters are :complete (finds only complete MIME::Types) and :platform (finds only MIME::Types for the current platform). It is possible for multiple matches to be returned for either type (in the example below, ‘text/plain’ returns two values — one for the general case, and one for VMS systems.
puts "\nMIME::Types['text/plain']" MIME::Types['text/plain'].each { |t| puts t.to_a.join(", ") } puts "\nMIME::Types[/^image/, :complete => true]" MIME::Types[/^image/, :complete => true].each do |t| puts t.to_a.join(", ") end
type_for(filename, platform = false) |
Return the list of MIME::Types which belongs to the file based on its filename extension. If platform is true, then only file types that are specific to the current platform will be returned.
puts "MIME::Types.type_for('citydesk.xml') => "#{MIME::Types.type_for('citydesk.xml')}" puts "MIME::Types.type_for('citydesk.gif') => "#{MIME::Types.type_for('citydesk.gif')}"
of(filename, platform = false) |
A synonym for MIME::Types.type_for
add(*types) |
Add one or more MIME::Type objects to the set of known types. Each type should be experimental (e.g., ‘application/x-ruby’). If the type is already known, a warning will be displayed.
Please inform the maintainer of this module when registered types are missing.