Class: Async::HTTP::Headers
- Inherits:
-
Object
- Object
- Async::HTTP::Headers
- Defined in:
- lib/async/http/headers.rb
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #delete(key) ⇒ Object
- #each ⇒ Object
- #freeze ⇒ Object
-
#initialize ⇒ Headers
constructor
A new instance of Headers.
- #inspect ⇒ Object
- #stringify(key) ⇒ Object
- #symbolize(value) ⇒ Object
- #to_hash ⇒ Object
- #to_http_hash ⇒ Object
Constructor Details
#initialize ⇒ Headers
Returns a new instance of Headers.
24 25 26 |
# File 'lib/async/http/headers.rb', line 24 def initialize @hash = {} end |
Class Method Details
.[](value) ⇒ Object
80 81 82 |
# File 'lib/async/http/headers.rb', line 80 def self.[] value value.downcase.tr('-', '_').to_sym end |
Instance Method Details
#==(other) ⇒ Object
48 49 50 |
# File 'lib/async/http/headers.rb', line 48 def == other @hash == other.to_hash end |
#[](key) ⇒ Object
44 45 46 |
# File 'lib/async/http/headers.rb', line 44 def [] key @hash[key] end |
#[]=(key, value) ⇒ Object
40 41 42 |
# File 'lib/async/http/headers.rb', line 40 def []= key, value @hash[symbolize(key)] = value end |
#delete(key) ⇒ Object
52 53 54 |
# File 'lib/async/http/headers.rb', line 52 def delete(key) @hash.delete(key) end |
#each ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/async/http/headers.rb', line 56 def each return to_enum unless block_given? @hash.each do |key, value| yield stringify(key), value end end |
#freeze ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/async/http/headers.rb', line 28 def freeze return unless frozen? @hash.freeze super end |
#inspect ⇒ Object
36 37 38 |
# File 'lib/async/http/headers.rb', line 36 def inspect @hash.inspect end |
#stringify(key) ⇒ Object
68 69 70 |
# File 'lib/async/http/headers.rb', line 68 def stringify(key) key.to_s.tr('_', '-') end |
#symbolize(value) ⇒ Object
64 65 66 |
# File 'lib/async/http/headers.rb', line 64 def symbolize(value) Headers[value] end |
#to_hash ⇒ Object
72 73 74 |
# File 'lib/async/http/headers.rb', line 72 def to_hash @hash end |
#to_http_hash ⇒ Object
76 77 78 |
# File 'lib/async/http/headers.rb', line 76 def to_http_hash Hash[@hash.map{|key, value| ["HTTP_#{key.to_s.upcase}", value]}] end |