Class: HTTP::ContentType
- Inherits:
-
Object
- Object
- HTTP::ContentType
- Defined in:
- lib/http/content_type.rb
Overview
Parsed representation of a Content-Type header
Constant Summary collapse
- MIME_TYPE_RE =
Pattern for extracting MIME type from Content-Type header
%r{^([^/]+/[^;]+)(?:$|;)}- CHARSET_RE =
Pattern for extracting charset from Content-Type header
/;\s*charset=([^;]+)/i
Instance Attribute Summary collapse
-
#charset ⇒ String?
Character set of the content.
-
#mime_type ⇒ String?
MIME type of the content.
Class Method Summary collapse
-
.parse(str) ⇒ ContentType
Parse string and return ContentType object.
Instance Method Summary collapse
-
#deconstruct_keys(keys) ⇒ Hash{Symbol => Object}
Pattern matching interface for matching against content type attributes.
-
#initialize(mime_type = nil, charset = nil) ⇒ ContentType
constructor
Create a new ContentType instance.
Constructor Details
#initialize(mime_type = nil, charset = nil) ⇒ ContentType
Create a new ContentType instance
68 69 70 71 |
# File 'lib/http/content_type.rb', line 68 def initialize(mime_type = nil, charset = nil) @mime_type = mime_type @charset = charset end |
Instance Attribute Details
#charset ⇒ String?
Character set of the content
27 28 29 |
# File 'lib/http/content_type.rb', line 27 def charset @charset end |
#mime_type ⇒ String?
MIME type of the content
18 19 20 |
# File 'lib/http/content_type.rb', line 18 def mime_type @mime_type end |
Class Method Details
.parse(str) ⇒ ContentType
Parse string and return ContentType object
38 39 40 |
# File 'lib/http/content_type.rb', line 38 def parse(str) new mime_type(str), charset(str) end |
Instance Method Details
#deconstruct_keys(keys) ⇒ Hash{Symbol => Object}
Pattern matching interface for matching against content type attributes
84 85 86 87 |
# File 'lib/http/content_type.rb', line 84 def deconstruct_keys(keys) hash = { mime_type: @mime_type, charset: @charset } keys ? hash.slice(*keys) : hash end |