Class: Protocol::HTTP::Header::Split

Inherits:
Array
  • Object
show all
Defined in:
lib/protocol/http/header/split.rb

Overview

Represents headers that can contain multiple distinct values separated by commas.

This isn’t a specific header class is a utility for handling headers with comma-separated values, such as ‘accept`, `cache-control`, and other similar headers. The values are split and stored as an array internally, and serialized back to a comma-separated string when needed.

Constant Summary collapse

COMMA =

Regular expression used to split values on commas, with optional surrounding whitespace.

/\s*,\s*/

Instance Method Summary collapse

Constructor Details

#initialize(value = nil) ⇒ Split

Initializes a ‘Split` header with the given value. If the value is provided, it is split into distinct entries and stored as an array.



19
20
21
22
23
24
25
# File 'lib/protocol/http/header/split.rb', line 19

def initialize(value = nil)
	if value
		super(value.split(COMMA))
	else
		super()
	end
end

Instance Method Details

#<<(value) ⇒ Object

Adds one or more comma-separated values to the header.

The input string is split into distinct entries and appended to the array.



32
33
34
# File 'lib/protocol/http/header/split.rb', line 32

def << value
	self.concat(value.split(COMMA))
end

#to_sObject

Serializes the stored values into a comma-separated string.



39
40
41
# File 'lib/protocol/http/header/split.rb', line 39

def to_s
	join(",")
end