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

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, line 25
def matches(language)
  values.select {|v|
    v == language || v == '*' || (language.match(/^(.+?)-/) && v == $1)
  }.sort {|a, b|
    # "*" gets least precedence, any others are compared based on length.
    a == '*' ? -1 : (b == '*' ? 1 : a.length <=> b.length)
  }.reverse
end
name() click to toggle source

The name of this header.

# File lib/rack/accept/language.rb, line 11
def name
  'Accept-Language'
end
qvalue(language) click to toggle source

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

# File lib/rack/accept/language.rb, line 16
def qvalue(language)
  return 1 if @qvalues.empty?
  m = matches(language)
  return 0 if m.empty?
  normalize_qvalue(@qvalues[m.first])
end