Class: Resourceful::Header
Constant Summary collapse
- HEADERS =
%w[ Accept Accept-Charset Accept-Encoding Accept-Language Accept-Ranges Age Allow Authorization Cache-Control Connection Content-Encoding Content-Language Content-Length Content-Location Content-MD5 Content-Range Content-Type Date ETag Expect Expires From Host If-Match If-Modified-Since If-None-Match If-Range If-Unmodified-Since Keep-Alive Last-Modified Location Max-Forwards Pragma Proxy-Authenticate Proxy-Authorization Range Referer Retry-After Server TE Trailer Transfer-Encoding Upgrade User-Agent Vary Via Warning WWW-Authenticate ]
- HOP_BY_HOP_HEADERS =
[ CONNECTION, KEEP_ALIVE, PROXY_AUTHENTICATE, PROXY_AUTHORIZATION, TE, TRAILER, TRANSFER_ENCODING, UPGRADE ].freeze
- NON_MODIFIABLE_HEADERS =
[ CONTENT_LOCATION, CONTENT_MD5, ETAG, LAST_MODIFIED, EXPIRES ].freeze
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, v) ⇒ Object
- #capitalize(k) ⇒ Object
- #each_field(&blk) ⇒ Object
- #has_key?(k) ⇒ Boolean
-
#initialize(hash = {}) ⇒ Header
constructor
A new instance of Header.
- #to_hash ⇒ Object
Constructor Details
#initialize(hash = {}) ⇒ Header
Returns a new instance of Header.
5 6 7 |
# File 'lib/resourceful/header.rb', line 5 def initialize(hash={}) hash.each { |k, v| self[k] = v } end |
Instance Method Details
#[](k) ⇒ Object
13 14 15 |
# File 'lib/resourceful/header.rb', line 13 def [](k) super capitalize(k) end |
#[]=(k, v) ⇒ Object
17 18 19 |
# File 'lib/resourceful/header.rb', line 17 def []=(k, v) super capitalize(k), v end |
#capitalize(k) ⇒ Object
25 26 27 |
# File 'lib/resourceful/header.rb', line 25 def capitalize(k) k.to_s.downcase.gsub(/^.|[-_\s]./) { |x| x.upcase }.gsub('_', '-') end |
#each_field(&blk) ⇒ Object
29 30 31 32 33 |
# File 'lib/resourceful/header.rb', line 29 def each_field(&blk) to_hash.each { |k,v| blk.call capitalize(k), v } end |
#has_key?(k) ⇒ Boolean
21 22 23 |
# File 'lib/resourceful/header.rb', line 21 def has_key?(k) super capitalize(k) end |
#to_hash ⇒ Object
9 10 11 |
# File 'lib/resourceful/header.rb', line 9 def to_hash {}.replace(self) end |