Class: SRL::ResultSet
- Inherits:
-
Object
- Object
- SRL::ResultSet
- Defined in:
- lib/srl/typedefs.rb
Overview
Wrapper around various calls to paginated data, such as past races. Contains pagination information, and information on all records, on top of the current page’s records.
Instance Attribute Summary collapse
-
#count ⇒ Object
(also: #total_records, #num_records)
readonly
Total number of records matching the query for this result set.
-
#page ⇒ Object
readonly
The page of this result set.
-
#page_size ⇒ Object
(also: #per_page)
readonly
Returns the value of attribute page_size.
-
#results ⇒ Object
(also: #data, #records, #items)
readonly
Records for this result set.
Instance Method Summary collapse
-
#initialize(results, params = {}) ⇒ ResultSet
constructor
A new instance of ResultSet.
- #last_page? ⇒ Boolean
- #num_pages ⇒ Object (also: #pages)
Constructor Details
#initialize(results, params = {}) ⇒ ResultSet
Returns a new instance of ResultSet.
321 322 323 324 325 326 |
# File 'lib/srl/typedefs.rb', line 321 def initialize(results, params = {}) @results = results @page = params.fetch(:page) @page_size = params.fetch(:page_size) @count = params.fetch(:count) end |
Instance Attribute Details
#count ⇒ Object (readonly) Also known as: total_records, num_records
Total number of records matching the query for this result set.
317 318 319 |
# File 'lib/srl/typedefs.rb', line 317 def count @count end |
#page ⇒ Object (readonly)
The page of this result set.
311 312 313 |
# File 'lib/srl/typedefs.rb', line 311 def page @page end |
#page_size ⇒ Object (readonly) Also known as: per_page
Returns the value of attribute page_size.
313 314 315 |
# File 'lib/srl/typedefs.rb', line 313 def page_size @page_size end |
#results ⇒ Object (readonly) Also known as: data, records, items
Records for this result set.
- NOTE
-
Always an array, though the type of object contained in the array can vary depending on the query that spawned it.
305 306 307 |
# File 'lib/srl/typedefs.rb', line 305 def results @results end |
Instance Method Details
#last_page? ⇒ Boolean
333 334 335 |
# File 'lib/srl/typedefs.rb', line 333 def last_page? page == num_pages end |
#num_pages ⇒ Object Also known as: pages
328 329 330 |
# File 'lib/srl/typedefs.rb', line 328 def num_pages (count.to_f / page_size.to_f).ceil end |