Class: RMeetup::Collection
- Inherits:
-
Array
- Object
- Array
- RMeetup::Collection
- Defined in:
- lib/rmeetup/collection.rb
Instance Attribute Summary collapse
-
#current_page ⇒ Object
WillPaginate Helper Methods.
-
#page_size ⇒ Object
Returns the value of attribute page_size.
-
#total_results ⇒ Object
Returns the value of attribute total_results.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#current_page ⇒ Object
WillPaginate Helper Methods
These methods are implementded so that you may pass this collection to the will_paginate view helper to render pagination links.
30 31 32 |
# File 'lib/rmeetup/collection.rb', line 30 def current_page @current_page end |
#page_size ⇒ Object
Returns the value of attribute page_size.
3 4 5 |
# File 'lib/rmeetup/collection.rb', line 3 def page_size @page_size end |
#total_results ⇒ Object
Returns the value of attribute total_results.
3 4 5 |
# File 'lib/rmeetup/collection.rb', line 3 def total_results @total_results end |
Class Method Details
.build(response) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rmeetup/collection.rb', line 6 def self.build(response) collection = Collection.new() # Setup the attributes needed for WillPaginate style paging request_url = response['meta']['url'] request_parameters = parse_parameters_from_url(request_url) collection.page_size = request_parameters['page'] ? request_parameters['page'].to_i : nil collection.total_results = response['meta']['total_count'].to_i collection.current_page = request_parameters['offset'] ? (request_parameters['offset'].to_i + 1) : 1 # Load the collection with all # of the results we passed in response['results'].each do |result| collection << result end collection end |
Instance Method Details
#next_page ⇒ Object
42 43 44 |
# File 'lib/rmeetup/collection.rb', line 42 def next_page self.current_page == self.total_pages ? nil : self.current_page.to_i+1 end |
#previous_page ⇒ Object
38 39 40 |
# File 'lib/rmeetup/collection.rb', line 38 def previous_page self.current_page == 1 ? nil : self.current_page.to_i-1 end |
#total_pages ⇒ Object
34 35 36 |
# File 'lib/rmeetup/collection.rb', line 34 def total_pages @page_size ? (@total_results.to_f / @page_size.to_f).ceil : 1 end |