Class: Strava::Api::Pagination

Inherits:
Object
  • Object
show all
Includes:
Enumerable, DeepCopyable
Defined in:
lib/strava/api/pagination.rb

Overview

Wrapper Class around pagination results which are an Array of Models.

This class exists to provide a way to provide a high-level abstraction, like access to API request/response data (i.e. ratelimits) for paginated results.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DeepCopyable

#deep_copy

Constructor Details

#initialize(collection, web_response) ⇒ Pagination

Returns a new instance of Pagination.

Parameters:



21
22
23
24
# File 'lib/strava/api/pagination.rb', line 21

def initialize(collection, web_response)
  @collection = collection
  @web_response = web_response
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_symbol, *args, &block) ⇒ Object (private)



51
52
53
# File 'lib/strava/api/pagination.rb', line 51

def method_missing(method_symbol, *args, &block)
  @collection.send(method_symbol, *args, &block)
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



15
16
17
# File 'lib/strava/api/pagination.rb', line 15

def collection
  @collection
end

Instance Method Details

#eachObject



45
46
47
# File 'lib/strava/api/pagination.rb', line 45

def each
  @collection.each { |c| yield c if block_given? }
end

#http_responseStrava::Web::ApiResponse

getter method that calculates on access



31
32
33
34
# File 'lib/strava/api/pagination.rb', line 31

def http_response
  @http_response ||=
    Strava::Web::ApiResponse.new(deep_copy(@web_response).http_response)
end

#sizeInteger

delegates ‘size` to @collection

Returns:

  • (Integer)


41
42
43
# File 'lib/strava/api/pagination.rb', line 41

def size
  @collection.size
end