Class: SRL::ResultSet

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#countObject (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

#pageObject (readonly)

The page of this result set.



311
312
313
# File 'lib/srl/typedefs.rb', line 311

def page
  @page
end

#page_sizeObject (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

#resultsObject (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

Returns:

  • (Boolean)


333
334
335
# File 'lib/srl/typedefs.rb', line 333

def last_page?
  page == num_pages
end

#num_pagesObject 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