Sha256: 137801b5a496ef2baad93faa41cfbb6ba6260947600af803f7dc5e847f60d5d2

Contents?: true

Size: 597 Bytes

Versions: 2

Compression:

Stored size: 597 Bytes

Contents

require 'forwardable'

module Trav3
  class Headers
    extend Forwardable
    def_delegators :@heads, :each_pair

    def initialize(**args)
      build(**args)
    end

    def build(**args)
      @heads ||= {}

      args.each do |(key, value)|
        @heads[key] = value
      end

      self
    end

    def remove(key)
      @heads.delete(key)
    end

    def +(other)
      raise TypeError, "Headers type expected, #{other.class} given" unless other.is_a? Headers

      @heads.merge(other.instance_variable_get(:@heads))

      self
    end

    def to_h
      @heads
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
trav3-0.2.2 lib/trav3/headers.rb
trav3-0.2.1 lib/trav3/headers.rb