rdavid1099/poke-api-v2

View on GitHub
lib/poke_api/api_resource_list.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
module PokeApi
  # Base class handling all unnamed resource calls
  class ApiResourceList
    include AssignmentHelpers

    attr_reader :count,
                :next_url,
                :previous_url,
                :results

    def initialize(data)
      @count = data[:count]
      @next_url = data[:next]
      @previous_url = data[:previous]
      @results = assign_list(
        data: data[:results],
        klass: ENDPOINT_OBJECTS[data[:resource_name]]
      )
    end
  end
end