rootstrap/best_buy_ruby

View on GitHub
lib/best_buy/models/collections_response.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true

require 'best_buy'

module BestBuy
  class CollectionsResponse
    attr_reader :header, :collection

    def initialize(response:, collection_name:, collection_type:)
      header_hash = response.except(collection_name)
      collection_hash = response[collection_name]

      @header = CollectionHeader.new(header_hash)
      @collection = collection_hash.map do |collection_item|
        collection_type.new(collection_item)
      end
    end
  end
end