Class: Protocol::HTTP::Header::AcceptCharset

Inherits:
Split
  • Object
show all
Defined in:
lib/protocol/http/header/accept_charset.rb

Overview

The ‘accept-charset` header represents a list of character sets that the client can accept.

Defined Under Namespace

Classes: Charset

Constant Summary collapse

ParseError =
Class.new(Error)
CHARSET =
/\A(?<name>#{TOKEN})(;q=(?<q>#{QVALUE}))?\z/

Constants inherited from Split

Split::COMMA

Instance Method Summary collapse

Methods inherited from Split

#<<, #initialize, #to_s

Constructor Details

This class inherits a constructor from Protocol::HTTP::Header::Split

Instance Method Details

#charsetsObject

Parse the ‘accept-charset` header value into a list of character sets.



33
34
35
36
37
38
39
40
41
# File 'lib/protocol/http/header/accept_charset.rb', line 33

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