Class: OpenCongressApi::Collection
- Inherits:
-
Array
- Object
- Array
- OpenCongressApi::Collection
- Defined in:
- lib/opencongress_api/collection.rb
Instance Attribute Summary collapse
-
#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.
-
#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.
28 29 30 |
# File 'lib/opencongress_api/collection.rb', line 28 def current_page @current_page end |
#page_size ⇒ Object
Returns the value of attribute page_size.
3 4 5 |
# File 'lib/opencongress_api/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/opencongress_api/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 |
# File 'lib/opencongress_api/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.each do |result| collection << result end collection end |
Instance Method Details
#next_page ⇒ Object
40 41 42 |
# File 'lib/opencongress_api/collection.rb', line 40 def next_page self.current_page == self.total_pages ? nil : self.current_page.to_i+1 end |
#previous_page ⇒ Object
36 37 38 |
# File 'lib/opencongress_api/collection.rb', line 36 def previous_page self.current_page == 1 ? nil : self.current_page.to_i-1 end |
#total_pages ⇒ Object
32 33 34 |
# File 'lib/opencongress_api/collection.rb', line 32 def total_pages @page_size ? (@total_results.to_f / @page_size.to_f).ceil : 1 end |