A mediatype parameter such as one you'd find in an Accept
header.
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
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
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