class Strelka::HTTPRequest::Language
A natural language specification parameter, such as one you'd find in an Accept-Language
header.
Public Class Methods
parse( accept_param )
click to toggle source
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
language_range()
click to toggle source
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
to_s()
click to toggle source
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