Class: Protocol::HTTP::Header::AcceptLanguage
- Defined in:
- lib/protocol/http/header/accept_language.rb
Overview
The ‘accept-language` header represents a list of languages that the client can accept.
Defined Under Namespace
Classes: Language
Constant Summary collapse
- ParseError =
Class.new(Error)
- NAME =
/\*|[A-Z]{1,8}(-[A-Z0-9]{1,8})*/i
- QVALUE =
/0(\.[0-9]{0,6})?|1(\.[0]{0,6})?/
- LANGUAGE =
/\A(?<name>#{NAME})(\s*;\s*q=(?<q>#{QVALUE}))?\z/
Constants inherited from Split
Instance Method Summary collapse
-
#languages ⇒ Object
Parse the ‘accept-language` header value into a list of languages.
Methods inherited from Split
Constructor Details
This class inherits a constructor from Protocol::HTTP::Header::Split
Instance Method Details
#languages ⇒ Object
Parse the ‘accept-language` header value into a list of languages.
39 40 41 42 43 44 45 46 47 |
# File 'lib/protocol/http/header/accept_language.rb', line 39 def languages self.map do |value| if match = value.match(LANGUAGE) Language.new(match[:name], match[:q]) else raise ParseError.new("Could not parse language: #{value.inspect}") end end end |