Class: Strelka::HTTPRequest::Language
- Inherits:
-
AcceptParam
- Object
- AcceptParam
- Strelka::HTTPRequest::Language
- Defined in:
- lib/strelka/httprequest/acceptparams.rb
Overview
A natural language specification parameter, such as one you’d find in an Accept-Language header.
Constant Summary
Constants inherited from AcceptParam
AcceptParam::Q_DEFAULT, AcceptParam::Q_MAX
Instance Attribute Summary
Attributes inherited from AcceptParam
#extensions, #qvalue, #subtype, #type
Class Method Summary collapse
-
.parse(accept_param) ⇒ Object
Parse the given
accept_paramas a language range and return a Strelka::HTTPRequest::Language object for it.
Instance Method Summary collapse
-
#language_range ⇒ Object
Return the language range of the parameter as a String.
-
#to_s ⇒ Object
Return the parameter as a String suitable for inclusion in an Accept-language header.
Methods inherited from AcceptParam
#<=>, #=~, #extension_strings, #initialize, #inspect, #qvaluestring
Methods included from AbstractClass
extended, included, #inherited, #pure_virtual
Constructor Details
This class inherits a constructor from Strelka::HTTPRequest::AcceptParam
Class Method Details
.parse(accept_param) ⇒ Object
Parse the given accept_param as a language range and return a Strelka::HTTPRequest::Language object for it.
254 255 256 257 258 259 260 |
# File 'lib/strelka/httprequest/acceptparams.rb', line 254 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 |
Instance Method Details
#language_range ⇒ Object
Return the language range of the parameter as a String.
271 272 273 |
# File 'lib/strelka/httprequest/acceptparams.rb', line 271 def language_range return [ self.primary_tag, self.subtag ].compact.join( '-' ) end |
#to_s ⇒ Object
Return the parameter as a String suitable for inclusion in an Accept-language header.
277 278 279 280 281 282 283 |
# File 'lib/strelka/httprequest/acceptparams.rb', line 277 def to_s return [ self.language_range, self.qvaluestring, self.extension_strings, ].compact.join( ';' ) end |