summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Menard <kevin@nirvdrum.com>2021-01-17 00:36:50 -0500
committerGitHub <noreply@github.com>2021-01-17 00:36:50 -0500
commit4cc6ef8fac112080f89acca357d7b6e0272dd553 (patch)
tree3576991353901089f3a8805938ab840dcebba836
parent156aba6209ad831305fb20ad729f11a61d146a3a (diff)
downloadmime-types-4cc6ef8fac112080f89acca357d7b6e0272dd553.tar.gz
Doc fixes (#153)
* Update rdoc overview to match README. * Fix a typo. * Update `simplified` docs to match new semantics.
-rw-r--r--lib/mime/type.rb64
1 files changed, 49 insertions, 15 deletions
diff --git a/lib/mime/type.rb b/lib/mime/type.rb
index 07e1ad3..9035a73 100644
--- a/lib/mime/type.rb
+++ b/lib/mime/type.rb
@@ -9,25 +9,60 @@ end
# == Usage
# require 'mime/types'
#
-# plaintext = MIME::Types['text/plain'].first
-# # returns [text/plain, text/plain]
+# plaintext = MIME::Types['text/plain'] # => [ text/plain ]
# text = plaintext.first
-# print text.media_type # => 'text'
-# print text.sub_type # => 'plain'
+# puts text.media_type # => 'text'
+# puts text.sub_type # => 'plain'
#
-# puts text.extensions.join(" ") # => 'asc txt c cc h hh cpp'
+# puts text.extensions.join(' ') # => 'txt asc c cc h hh cpp hpp dat hlp'
+# puts text.preferred_extension # => 'txt'
+# puts text.friendly # => 'Text Document'
+# puts text.i18n_key # => 'text.plain'
#
-# puts text.encoding # => 8bit
+# puts text.encoding # => quoted-printable
+# puts text.default_encoding # => quoted-printable
# puts text.binary? # => false
# puts text.ascii? # => true
+# puts text.obsolete? # => false
+# puts text.registered? # => true
+# puts text.complete? # => true
+#
+# puts text # => 'text/plain'
+#
# puts text == 'text/plain' # => true
-# puts MIME::Type.simplified('x-appl/x-zip') # => 'appl/zip'
+# puts 'text/plain' == text # => true
+# puts text == 'text/x-plain' # => false
+# puts 'text/x-plain' == text # => false
+#
+# puts MIME::Type.simplified('x-appl/x-zip') # => 'x-appl/x-zip'
+# puts MIME::Type.i18n_key('x-appl/x-zip') # => 'x-appl.x-zip'
+#
+# puts text.like?('text/x-plain') # => true
+# puts text.like?(MIME::Type.new('x-text/x-plain')) # => true
+#
+# puts text.xrefs.inspect # => { "rfc" => [ "rfc2046", "rfc3676", "rfc5147" ] }
+# puts text.xref_urls # => [ "http://www.iana.org/go/rfc2046",
+# # "http://www.iana.org/go/rfc3676",
+# # "http://www.iana.org/go/rfc5147" ]
+#
+# xtext = MIME::Type.new('x-text/x-plain')
+# puts xtext.media_type # => 'text'
+# puts xtext.raw_media_type # => 'x-text'
+# puts xtext.sub_type # => 'plain'
+# puts xtext.raw_sub_type # => 'x-plain'
+# puts xtext.complete? # => false
+#
+# puts MIME::Types.any? { |type| type.content_type == 'text/plain' } # => true
+# puts MIME::Types.all?(&:registered?) # => false
+#
+# # Various string representations of MIME types
+# qcelp = MIME::Types['audio/QCELP'].first # => audio/QCELP
+# puts qcelp.content_type # => 'audio/QCELP'
+# puts qcelp.simplified # => 'audio/qcelp'
#
-# puts MIME::Types.any? { |type|
-# type.content_type == 'text/plain'
-# } # => true
-# puts MIME::Types.all?(&:registered?)
-# # => false
+# xwingz = MIME::Types['application/x-Wingz'].first # => application/x-Wingz
+# puts xwingz.content_type # => 'application/x-Wingz'
+# puts xwingz.simplified # => 'application/x-wingz'
class MIME::Type
# Reflects a MIME content-type specification that is not correctly
# formatted (it isn't +type+/+subtype+).
@@ -74,7 +109,7 @@ class MIME::Type
:ASCII_ENCODINGS
# Builds a MIME::Type object from the +content_type+, a MIME Content Type
- # value (e.g., 'text/plain' or 'applicaton/x-eruby'). The constructed object
+ # value (e.g., 'text/plain' or 'application/x-eruby'). The constructed object
# is yielded to an optional block for additional configuration, such as
# associating extensions and encoding information.
#
@@ -197,8 +232,7 @@ class MIME::Type
# audio/QCELP => audio/QCELP
attr_reader :content_type
# A simplified form of the MIME content-type string, suitable for
- # case-insensitive comparison, with any extension markers (<tt>x-</tt)
- # removed and converted to lowercase.
+ # case-insensitive comparison, with the content_type converted to lowercase.
#
# text/plain => text/plain
# x-chemical/x-pdb => x-chemical/x-pdb