Strelka::HTTPRequest::

MediaType

class
Superclass
Strelka::HTTPRequest::AcceptParam

A mediatype parameter such as one you'd find in an Accept header.

Public Class Methods

anchor
parse( accept_param )

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

anchor
content_type()
Alias for: mediatype
anchor
mediatype()

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
anchor
mimetype()
Alias for: mediatype
anchor
to_s()

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