class Strelka::HTTPRequest::MediaType
A mediatype parameter such as one you'd find in an Accept
header.
Public Class Methods
parse( accept_param )
click to toggle source
Parse the given accept_param
as a mediatype and return a Strelka::HTTPRequest::MediaType
object for it.
# File lib/strelka/httprequest/acceptparams.rb, line 214 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
Public Instance Methods
mediatype()
click to toggle source
The mediatype of the parameter, consisting of the type and subtype separated by '/'.
# File lib/strelka/httprequest/acceptparams.rb, line 227 def mediatype return "%s/%s" % [ self.type || '*', self.subtype || '*' ] end
Also aliased as: mimetype, content_type
to_s()
click to toggle source
Return the parameter as a String suitable for inclusion in an Accept HTTP header
# File lib/strelka/httprequest/acceptparams.rb, line 236 def to_s return [ self.mediatype, self.qvaluestring, self.extension_strings ].compact.join(';') end