Sha256: d87c1e540f5eb8dad0d5cdbcf223d6a26c904bfb1b556e30aa05ecedfd4a9824

Contents?: true

Size: 628 Bytes

Versions: 3

Compression:

Stored size: 628 Bytes

Contents

# frozen_string_literal: true

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

3 entries across 3 versions & 1 rubygems

Version Path
trav3-0.2.5 lib/trav3/headers.rb
trav3-0.2.4 lib/trav3/headers.rb
trav3-0.2.3 lib/trav3/headers.rb