A natural language specification parameter, such as one you'd find in
an Accept-Language
header.
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
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
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