class AcceptCharset < Split
- Inherits from
Split: #<<, #to_s, #sort_by_quality_factor, .parse, .coerce, .trailer?
The accept-charset header represents a list of character sets that the client can accept.
Nested Classes and Modules
class CharsetA parsed character set entry with an optional quality factor.
Definitions
CHARSET = /\A(?<name>#{TOKEN})(;q=(?<q>#{QVALUE}))?\z/
https://tools.ietf.org/html/rfc7231#section-5.3.3
def charsets
Parse the accept-charset header value into a list of character sets.
Signature
-
returns
Array(Charset) the list of character sets and their associated quality factors.
Implementation
def charsets
self.map do |value|
if match = value.match(CHARSET)
Charset.new(match[:name], match[:q])
else
raise ParseError.new("Could not parse character set: #{value.inspect}")
end
end
end
def preferred_charsets
Parse the accept-charset header and order character sets by preference.
Character sets with equal quality factors retain their original relative order.
Signature
-
returns
Array(Charset) the preferred character sets.
Implementation
def preferred_charsets
sort_by_quality_factor(charsets)
end