Class: Protocol::HTTP::Headers::Merged

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/protocol/http/headers.rb

Overview

Used for merging objects into a sequential list of headers. Normalizes header keys and values.

Instance Method Summary collapse

Constructor Details

#initialize(*all) ⇒ Merged

Construct a merged list of headers.



389
390
391
# File 'lib/protocol/http/headers.rb', line 389

def initialize(*all)
	@all = all
end

Instance Method Details

#<<(headers) ⇒ Object

Add a new set of headers to the merged list.



411
412
413
414
415
# File 'lib/protocol/http/headers.rb', line 411

def << headers
	@all << headers
	
	return self
end

#clearObject

Clear the references to all headers.



404
405
406
# File 'lib/protocol/http/headers.rb', line 404

def clear
	@all.clear
end

#each(&block) ⇒ Object

Enumerate all headers in the merged list.



422
423
424
425
426
427
428
429
430
# File 'lib/protocol/http/headers.rb', line 422

def each(&block)
	return to_enum unless block_given?
	
	@all.each do |headers|
		headers.each do |key, value|
			yield key.to_s.downcase, value.to_s
		end
	end
end

#fieldsObject



394
395
396
# File 'lib/protocol/http/headers.rb', line 394

def fields
	each.to_a
end

#flattenObject



399
400
401
# File 'lib/protocol/http/headers.rb', line 399

def flatten
	Headers.new(fields)
end