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.



520
521
522
# File 'lib/protocol/http/headers.rb', line 520

def initialize(*all)
	@all = all
end

Instance Method Details

#<<(headers) ⇒ Object

Add a new set of headers to the merged list.



542
543
544
545
546
# File 'lib/protocol/http/headers.rb', line 542

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

#clearObject

Clear the references to all headers.



535
536
537
# File 'lib/protocol/http/headers.rb', line 535

def clear
	@all.clear
end

#each(&block) ⇒ Object

Enumerate all headers in the merged list.



553
554
555
556
557
558
559
560
561
# File 'lib/protocol/http/headers.rb', line 553

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



525
526
527
# File 'lib/protocol/http/headers.rb', line 525

def fields
	each.to_a
end

#flattenObject



530
531
532
# File 'lib/protocol/http/headers.rb', line 530

def flatten
	Headers.new(fields)
end