lib/trav3/headers.rb in trav3-0.3.4 vs lib/trav3/headers.rb in trav3-0.4.0

- old
+ new

@@ -3,37 +3,49 @@ require 'forwardable' module Trav3 class Headers extend Forwardable - def_delegators :@heads, :each_pair + def_delegators :@heads, :each_pair, :fetch def initialize(args = {}) build(args) end + # Add or update the request headers + # + # @return [Headers] self def build(args = {}) @heads ||= {} args.each do |(key, value)| @heads[key] = value end self end + # Remove key/value from headers via key + # + # @param key [Symbol, String] key to look up + # @return [String, Symbol, nil] returns value if key found, `nil` otherwise. def remove(key) @heads.delete(key) end + # Add the values of one `Headers` into another + # + # @param other [Headers] instance of `Headers` + # @return [Headers] def +(other) raise TypeError, "Headers type expected, #{other.class} given" unless other.is_a? Headers @heads.merge(other.instance_variable_get(:@heads)) self end + # @return [Hash] hash of the `Headers` def to_h @heads end end end