class Hurley::Header
Constants
- DASH
- KEYS
hash of “shortcut key” => “canonical header key” string keys are converted to canonical header names:
KEYS # => “Content-Type”
- UNDERSCORE
Public Class Methods
add_canonical_key(*canonicals)
click to toggle source
# File lib/hurley/header.rb, line 63 def self.add_canonical_key(*canonicals) canonicals.each do |canonical| canonical.freeze KEYS[canonical] = canonical shortcut = canonical.downcase KEYS[shortcut.freeze] = canonical KEYS[shortcut.tr(DASH, UNDERSCORE).to_sym] = canonical end end
canonical(input)
click to toggle source
# File lib/hurley/header.rb, line 54 def self.canonical(input) KEYS[input] || begin key = input.to_s.tr(UNDERSCORE, DASH) key.downcase! key.gsub!(/(\A|\-)(\S)/) { |s| s.upcase! ; s } key end end
new(initial = nil)
click to toggle source
# File lib/hurley/header.rb, line 5 def initialize(initial = nil) @hash = {} update(initial) if initial end
Public Instance Methods
[](key)
click to toggle source
# File lib/hurley/header.rb, line 17 def [](key) @hash[self.class.canonical(key)] end
[]=(key, value)
click to toggle source
# File lib/hurley/header.rb, line 21 def []=(key, value) @hash[self.class.canonical(key)] = value.to_s end
delete(key)
click to toggle source
# File lib/hurley/header.rb, line 29 def delete(key) @hash.delete(self.class.canonical(key)) end
dup()
click to toggle source
# File lib/hurley/header.rb, line 39 def dup self.class.new(@hash.dup) end
inspect()
click to toggle source
# File lib/hurley/header.rb, line 47 def inspect "#<%s %s>" % [ self.class.name, @hash.inspect, ] end
key?(key)
click to toggle source
# File lib/hurley/header.rb, line 25 def key?(key) @hash.key?(self.class.canonical(key)) end
to_hash()
click to toggle source
# File lib/hurley/header.rb, line 43 def to_hash @hash end
update(hash)
click to toggle source
# File lib/hurley/header.rb, line 33 def update(hash) hash.each do |key, value| self[key] = value end end