Sha256: 4800d7e632e9c202f25d71021b4bc68ca0e63e735a31555106c2bffeaa1d3a4b

Contents?: true

Size: 961 Bytes

Versions: 8

Compression:

Stored size: 961 Bytes

Contents

module Typhoeus
  class Header < ::Hash
    def initialize(constructor = {})
      if constructor.is_a?(Hash)
        super
        update(constructor)
      else
        super(constructor)
      end
    end

    def fetch(key, *extras)
      super(convert_key(key), *extras)
    end

    def key?(key)
      super(convert_key(key))
    end

    def [](key)
      super(convert_key(key))
    end

    def []=(key, value)
      super(convert_key(key), value)
    end

    def update(other_hash)
      other_hash.each_pair do |key, value|
        self[convert_key(key)] = value
      end
      self
    end

    alias_method :merge!, :update

    def dup
      self.class.new(Marshal.load(Marshal.dump(self)))
    end

    def merge(hash)
      self.dup.update(hash)
    end

    def delete(key)
      super(convert_key(key))
    end

  private
    def convert_key(key)
      key.to_s.split(/_|-/).map { |segment| segment.capitalize }.join("-")
    end
  end
end

Version data entries

8 entries across 8 versions & 3 rubygems

Version Path
dcu-typhoeus-0.4.3 lib/typhoeus/header.rb
dcu-typhoeus-0.4.2 lib/typhoeus/header.rb
hhry-typhoeus-0.4.0 lib/typhoeus/header.rb
typhoeus-0.4.2 lib/typhoeus/header.rb
typhoeus-0.4.1 lib/typhoeus/header.rb
typhoeus-0.4.0 lib/typhoeus/header.rb
dcu-typhoeus-0.4.1 lib/typhoeus/header.rb
dcu-typhoeus-0.4.0 lib/typhoeus/header.rb