Strelka::HTTPRequest::

Language

class
Superclass
Strelka::HTTPRequest::AcceptParam

A natural language specification parameter, such as one you'd find in an Accept-Language header.

Public Class Methods

anchor
parse( accept_param )

Parse the given accept_param as a language range and return a Strelka::HTTPRequest::Language object for it.

# File lib/strelka/httprequest/acceptparams.rb, line 253
def self::parse( accept_param )
        language_range, *stuff = accept_param.split( /\s*;\s*/ )
        type, subtype = language_range.downcase.split( '-', 2 )
        qval, opts = stuff.partition {|par| par =~ /^q\s*=/ }

        return new( type, subtype, qval.first, *opts )
end

Public Instance Methods

anchor
language_range()

Return the language range of the parameter as a String.

# File lib/strelka/httprequest/acceptparams.rb, line 270
def language_range
        return [ self.primary_tag, self.subtag ].compact.join( '-' )
end
anchor
to_s()

Return the parameter as a String suitable for inclusion in an Accept-language header.

# File lib/strelka/httprequest/acceptparams.rb, line 276
def to_s
        return [
                self.language_range,
                self.qvaluestring,
                self.extension_strings,
        ].compact.join( ';' )
end