Summary
Definition of one MIME content-type
Synopsis
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'
content_type |
[R] |
Returns the whole MIME content-type string.
|
encoding |
[RW] |
The encoding (7bit, 8bit, quoted-printable, or base64) required to
transport the data of this content type safely across a network, which
roughly corresponds to Content-Transfer-Encoding. A value of nil
or :default will reset the #encoding to the #default_encoding for the MIME::Type. Raises ArgumentError if the encoding
provided is invalid.
|
extensions |
[RW] |
The list of extensions which are known to be used for this MIME::Type. Non-array values will be coerced into an
array with #to_a. Array values will be
flattened and nil values removed.
|
media_type |
[R] |
Returns the media type of the simplified MIME
type.
text/plain => text
x-chemical/x-pdb => chemical
|
raw_media_type |
[R] |
Returns the media type of the unmodified MIME
type.
text/plain => text
x-chemical/x-pdb => x-chemical
|
raw_sub_type |
[R] |
Returns the media type of the unmodified MIME
type.
text/plain => plain
x-chemical/x-pdb => x-pdb
|
simplified |
[R] |
The MIME types main- and sub-label can both
start with x-, which indicates that it is a non-registered name.
Of course, after registration this flag can disappear, adds to the
confusing proliferation of MIME types. The
simplified string has the x- removed and are translated to
lowercase.
|
sub_type |
[R] |
Returns the sub-type of the simplified MIME
type.
text/plain => plain
x-chemical/x-pdb => pdb
|
system |
[RW] |
The regexp for the operating system that this MIME::Type is specific to.
|
Comparable
The MIME types main- and sub-label can both
start with x-, which indicates that it is a non-registered name.
Of course, after registration this flag can disappear, adds to the
confusing proliferation of MIME types. The
simplified string has the x- removed and are translated to
lowercase.
Creates a MIME::Type from an array in the form of:
[type-name, [extensions], encoding, system]
extensions, encoding, and system are optional.
MIME::Type.from_array("application/x-ruby", ['rb'], '8bit')
MIME::Type.from_array(["application/x-ruby", ['rb'], '8bit'])
See MIME::Type.new for more information.
Creates a MIME::Type from a hash. Keys are
case-insensitive, dashes may be replaced with underscores, and the internal
Symbol of the lowercase-underscore version can be used as well. That is,
Content-Type can be provided as content-type,
Content_Type, content_type, or :content_type.
Acceptable keys are Content-Type,
Content-Transfer-Encoding, Extensions, and
System.
MIME::Type.from_hash('Content-Type' => 'text/x-yaml',
'Content-Transfer-Encoding' => '8bit',
'System' => 'linux',
'Extensions' => ['yaml', 'yml'])
See MIME::Type.new for more information.
arg may also be one of MIME::Type, Array,
or Hash.
- MIME::Type
- Equivalent to a copy constructor.
MIME::Type.new(plaintext)
MIME::Types are constructed with an alternative
object construction technique where self is +yield+ed after
initial construction.
MIME::Type.new('application/x-eruby') do |t|
t.extensions = 'rhtml'
t.encoding = '8bit'
end
Changes
In MIME::Types 1.07, the constructor accepted more
argument types and called #instance_eval on the optional block provided.
This is no longer the case as of 1.13. The full changes are noted below.
- The constructor +yield+s self instead of using #instance_eval and
that the calls to #init_extensions, #init_encoding, and #init_system have
been eliminated.
- MIME::Type.new no longer accepts a MIME::Type argument. Use MIME::Type.from_mime_type instead.
# 1.07
MIME::Type.new(plaintext)
# 1.12
MIME::Type.from_mime_type(plaintext)
- MIME::Type.new no longer accepts an Array
argument. Use MIME::Type.from_array
instead.
# 1.07
MIME::Type.new(["application/x-ruby", ["rb"], "8bit"])
# 1.12
MIME::Type.from_array("application/x-ruby", ['rb'], '8bit')
MIME::Type.from_array(["application/x-ruby", ['rb'], '8bit'])
- MIME::Type.new no longer accepts a Hash
argument. Use MIME::Type.from_hash instead.
# 1.07
MIME::Type.new('Content-Type' => 'text/x-yaml',
'Content-Transfer-Encoding' => '8bit',
'System' => 'linux',
'Extensions' => ['yaml', 'yml'])
# 1.12
MIME::Type.from_hash('Content-Type' => 'text/x-yaml',
'Content-Transfer-Encoding' => '8bit',
'System' => 'linux',
'Extensions' => ['yaml', 'yml'])
NOTE: | If the encoding is not specified, then it will be defaulted to
‘quoted-printable’ for ‘text/*’ media types and
‘base64’ for every other type. See #encoding for more
information.
|
Returns true if the simplified type matches the current
Returns the default encoding for the MIME::Type
based on the media type.
MIME content-types which are not regestered by
IANA nor defined in RFCs are required to start with x-. This
counts as well for a new media type as well as a new sub-type of an
existing media type. If either the media-type or the content-type begins
with x-, this method will return false.
MIME types can be specified to be sent across a
network in particular formats. This method returns true when the
MIME type encoding is set to base64.
MIME types can be specified to be sent across a
network in particular formats. This method returns false when the
MIME type encoding is set to base64.
Returns true when the simplified MIME
type is in the list of known digital signatures.
Returns true if the MIME::Type is specific
to an operating system.
Returns true if the MIME::Type is specific
to the current operating system as represented by RUBY_PLATFORM.
Returns true if the MIME::Type specifies
an extension list, indicating that it is a complete MIME::Type.
Returns the MIME type as a string.
Returns the MIME type as a string for implicit
conversions.