tylerhunt/brewery_db

View on GitHub
lib/brewery_db/collection.rb

Summary

Maintainability
A
0 mins
Test Coverage
module BreweryDB
  class Collection
    include Enumerable

    attr_reader :size
    alias length size

    def initialize(response)
      self.response = response
    end

    def each
      return to_enum unless block_given?
      @collection.each { |element| yield(element) }
    end

  private

    def response=(response)
      @response = response
      @collection = Array(response.data) || []
      @size = @collection.length
    end
  end
end