class Rack::Accept::Charset

Represents an HTTP Accept-Charset header according to the HTTP 1.1 specification, and provides several convenience methods for determining acceptable character sets.

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

Public Instance Methods

matches(charset) click to toggle source

Returns an array of character sets from this header that match the given charset, ordered by precedence.

# File lib/rack/accept/charset.rb, line 27
def matches(charset)
  values.select {|v|
    v == charset || v == '*'
  }.sort {|a, b|
    # "*" gets least precedence, any others should be equal.
    a == '*' ? 1 : (b == '*' ? -1 : 0)
  }
end
name() click to toggle source

The name of this header.

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

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

# File lib/rack/accept/charset.rb, line 16
def qvalue(charset)
  m = matches(charset)
  if m.empty?
    charset == 'iso-8859-1' ? 1 : 0
  else
    normalize_qvalue(@qvalues[m.first])
  end
end