class Songkick::Transport::Headers

Public Class Methods

new(hash) click to toggle source
Calls superclass method
# File lib/songkick/transport/headers.rb, line 7
def self.new(hash)
  return hash if self === hash
  super
end
new(hash = {}) click to toggle source
# File lib/songkick/transport/headers.rb, line 19
def initialize(hash = {})
  @hash = {}
  hash.each do |key, value|
    next if value.nil?
    @hash[self.class.normalize(key)] = value
  end
end
normalize(header_name) click to toggle source
# File lib/songkick/transport/headers.rb, line 12
def self.normalize(header_name)
  header_name.
      gsub(/^HTTP_/, '').gsub('_', '-').
      downcase.
      gsub(/(^|-)([a-z])/) { $1 + $2.upcase }
end

Public Instance Methods

==(other) click to toggle source
# File lib/songkick/transport/headers.rb, line 49
def ==(other)
  return false unless other.is_a?(self.class)
  to_hash == other.to_hash
end
[](header_name) click to toggle source
# File lib/songkick/transport/headers.rb, line 31
def [](header_name)
  @hash[self.class.normalize(header_name)]
end
[]=(header_name, value) click to toggle source
# File lib/songkick/transport/headers.rb, line 35
def []=(header_name, value)
  @hash[self.class.normalize(header_name)] = value
end
each(&block) click to toggle source
# File lib/songkick/transport/headers.rb, line 27
def each(&block)
  @hash.each(&block)
end
merge(hash) click to toggle source
# File lib/songkick/transport/headers.rb, line 39
def merge(hash)
  headers = self.class.new(to_hash)
  hash.each { |k,v| headers[k] = v }
  headers
end
to_hash() click to toggle source
# File lib/songkick/transport/headers.rb, line 45
def to_hash
  @hash.dup
end