Class: Rack::Accept::Charset
- Inherits:
-
Object
- Object
- Rack::Accept::Charset
- Includes:
- Header
- Defined in:
- lib/rack/accept/charset.rb
Overview
Represents an HTTP Accept-Charset header according to the HTTP 1.1 specification, and provides several convenience methods for determining acceptable character sets.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.2
Instance Attribute Summary
Attributes included from Header::PublicInstanceMethods
Instance Method Summary collapse
-
#matches(charset) ⇒ Object
Returns an array of character sets from this header that match the given
charset, ordered by precedence. -
#name ⇒ Object
The name of this header.
-
#qvalue(charset) ⇒ Object
Determines the quality factor (qvalue) of the given
charset.
Methods included from Header
join, normalize_qvalue, parse, parse_media_type, parse_range_params
Methods included from Header::PublicInstanceMethods
#accept?, #best_of, #initialize, #sort, #sort_with_qvalues, #to_s, #value, #values
Instance Method Details
#matches(charset) ⇒ Object
Returns an array of character sets from this header that match the given
charset, ordered by precedence.
27 28 29 30 31 32 33 34 |
# 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 ⇒ Object
The name of this header.
11 12 13 |
# File 'lib/rack/accept/charset.rb', line 11 def name 'Accept-Charset' end |
#qvalue(charset) ⇒ Object
Determines the quality factor (qvalue) of the given charset.
16 17 18 19 20 21 22 23 |
# 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 |