Class: ApiSports::Collection
- Inherits:
-
Object
- Object
- ApiSports::Collection
- Defined in:
- lib/api_sports/collection.rb
Instance Attribute Summary collapse
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
-
#total_pages ⇒ Object
readonly
Returns the value of attribute total_pages.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data:, total:, current_page:, total_pages:) ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize(data:, total:, current_page:, total_pages:) ⇒ Collection
Returns a new instance of Collection.
17 18 19 20 21 22 |
# File 'lib/api_sports/collection.rb', line 17 def initialize(data:, total:, current_page:, total_pages:) @data = data @total = total @current_page = current_page @total_pages = total_pages end |
Instance Attribute Details
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
5 6 7 |
# File 'lib/api_sports/collection.rb', line 5 def current_page @current_page end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/api_sports/collection.rb', line 5 def data @data end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
5 6 7 |
# File 'lib/api_sports/collection.rb', line 5 def total @total end |
#total_pages ⇒ Object (readonly)
Returns the value of attribute total_pages.
5 6 7 |
# File 'lib/api_sports/collection.rb', line 5 def total_pages @total_pages end |
Class Method Details
.from_response(response, type:, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/api_sports/collection.rb', line 7 def self.from_response(response, type:, &block) body = response.body new( data: block.nil? ? body["response"].map { |attrs| type.new(attrs) } : yield(body), total: body["results"], current_page: body["paging"]["current"], total_pages: body["paging"]["total"] ) end |