class Rack::Accept::Language

Represents an HTTP Accept-Language header according to the HTTP 1.1 specification, and provides several convenience methods for determining acceptable content languages.

www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4

Attributes

first_level_match[W]

Public Instance Methods

matches(language) click to toggle source

Returns an array of languages from this header that match the given language, ordered by precedence.

   # File lib/rack/accept/language.rb
26 def matches(language)
27   values.select {|v|
28     v = v.match(/^(.+?)-/) ? $1 : v if @first_level_match
29     v == language || v == '*' || (language.match(/^(.+?)-/) && v == $1)
30   }.sort {|a, b|
31     # "*" gets least precedence, any others are compared based on length.
32     a == '*' ? -1 : (b == '*' ? 1 : a.length <=> b.length)
33   }.reverse
34 end
name() click to toggle source

The name of this header.

   # File lib/rack/accept/language.rb
12 def name
13   'Accept-Language'
14 end
qvalue(language) click to toggle source

Determines the quality factor (qvalue) of the given language.

   # File lib/rack/accept/language.rb
17 def qvalue(language)
18   return 1 if @qvalues.empty?
19   m = matches(language)
20   return 0 if m.empty?
21   normalize_qvalue(@qvalues[m.first])
22 end