Class: Strelka::HTTPRequest::MediaType
- Inherits:
-
AcceptParam
- Object
- AcceptParam
- Strelka::HTTPRequest::MediaType
- Defined in:
- lib/strelka/httprequest/acceptparams.rb
Overview
A mediatype parameter such as one you'd find in an Accept header.
Constant Summary
Constants inherited from AcceptParam
AcceptParam::Q_DEFAULT, AcceptParam::Q_MAX
Instance Attribute Summary
Attributes inherited from AcceptParam
#extensions, #qvalue, #subtype, #type
Class Method Summary collapse
-
.parse(accept_param) ⇒ Object
Parse the given
accept_paramas a mediatype and return a Strelka::HTTPRequest::MediaType object for it.
Instance Method Summary collapse
-
#mediatype ⇒ Object
(also: #mimetype, #content_type)
The mediatype of the parameter, consisting of the type and subtype separated by '/'.
-
#to_s ⇒ Object
Return the parameter as a String suitable for inclusion in an Accept HTTP header.
Methods inherited from AcceptParam
#<=>, #=~, #extension_strings, #initialize, #inspect, #qvaluestring
Methods included from AbstractClass
extended, included, #inherited, #pure_virtual
Constructor Details
This class inherits a constructor from Strelka::HTTPRequest::AcceptParam
Class Method Details
.parse(accept_param) ⇒ Object
Parse the given accept_param as a mediatype and return a
Strelka::HTTPRequest::MediaType object for it.
215 216 217 218 219 220 221 222 223 |
# File 'lib/strelka/httprequest/acceptparams.rb', line 215 def self::parse( accept_param ) raise ArgumentError, "Bad Accept param: no media-range in %p" % [accept_param] unless accept_param.include?( '/' ) media_range, *stuff = accept_param.split( /\s*;\s*/ ) type, subtype = media_range.downcase.split( '/', 2 ) qval, opts = stuff.partition {|par| par =~ /^q\s*=/ } return new( type, subtype, qval.first, *opts ) end |
Instance Method Details
#mediatype ⇒ Object Also known as: mimetype, content_type
The mediatype of the parameter, consisting of the type and subtype separated by '/'.
228 229 230 |
# File 'lib/strelka/httprequest/acceptparams.rb', line 228 def mediatype return "%s/%s" % [ self.type || '*', self.subtype || '*' ] end |
#to_s ⇒ Object
Return the parameter as a String suitable for inclusion in an Accept HTTP header
237 238 239 240 241 242 243 |
# File 'lib/strelka/httprequest/acceptparams.rb', line 237 def to_s return [ self.mediatype, self.qvaluestring, self.extension_strings ].compact.join(';') end |