Sha256: a5e54b971688aab6f44e6edb2312059891d9bdb05df9ecafde89d94611d50bb6

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils'

module Aranha
  module Parsers
    class SourceAddress
      class HashHttpBase
        class Headers
          acts_as_immutable
          immutable_accessor :value, type: :hash

          # @!method to_h()
          # @return [Hash]
          delegate :to_h, to: :values

          # @param other_values [Array, Hash]
          # @return [Aranha::Parsers::SourceAddress::HashHttpBase::Headers]
          def merge(other_values)
            if other_values.is_a?(::Hash)
              values(values.merge(other_values))
            elsif other_values.is_a?(::Enumerable)
              merge(other_values.to_h { |v| merge_array_item_to_h(v) })
            else
              raise ::ArgumentError,
                    "\"other_values\"=\"#{other_values}\" should be a Array or a Hash"
            end
          end

          private

          # @param item [Array]
          # @return [Array
          def merge_array_item_to_h(item)
            2.times.inject(Array(item)) do |a, e|
              e >= a.count ? a + [nil] : a
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
aranha-parsers-0.25.0 lib/aranha/parsers/source_address/hash_http_base/headers.rb
aranha-parsers-0.24.0 lib/aranha/parsers/source_address/hash_http_base/headers.rb
aranha-parsers-0.23.1 lib/aranha/parsers/source_address/hash_http_base/headers.rb
aranha-parsers-0.23.0 lib/aranha/parsers/source_address/hash_http_base/headers.rb
aranha-parsers-0.22.0 lib/aranha/parsers/source_address/hash_http_base/headers.rb