Class: Zomato::Restaurant::Collection
- Inherits:
-
Object
- Object
- Zomato::Restaurant::Collection
- Defined in:
- lib/zomato/restaurant.rb
Instance Attribute Summary collapse
-
#restaurants ⇒ Object
readonly
Returns the value of attribute restaurants.
-
#results_found ⇒ Object
readonly
Returns the value of attribute results_found.
-
#results_shown ⇒ Object
readonly
Returns the value of attribute results_shown.
-
#results_start ⇒ Object
readonly
Returns the value of attribute results_start.
Instance Method Summary collapse
- #attributes ⇒ Object
- #first ⇒ Object
- #has_next_page? ⇒ Boolean
- #has_previous_page? ⇒ Boolean
-
#initialize(response, query) ⇒ Collection
constructor
A new instance of Collection.
- #last ⇒ Object
- #next_page! ⇒ Object
- #previous_page! ⇒ Object
- #total_pages ⇒ Object
Constructor Details
#initialize(response, query) ⇒ Collection
Returns a new instance of Collection.
7 8 9 |
# File 'lib/zomato/restaurant.rb', line 7 def initialize(response, query) load(response, query) end |
Instance Attribute Details
#restaurants ⇒ Object (readonly)
Returns the value of attribute restaurants.
5 6 7 |
# File 'lib/zomato/restaurant.rb', line 5 def restaurants @restaurants end |
#results_found ⇒ Object (readonly)
Returns the value of attribute results_found.
5 6 7 |
# File 'lib/zomato/restaurant.rb', line 5 def results_found @results_found end |
#results_shown ⇒ Object (readonly)
Returns the value of attribute results_shown.
5 6 7 |
# File 'lib/zomato/restaurant.rb', line 5 def results_shown @results_shown end |
#results_start ⇒ Object (readonly)
Returns the value of attribute results_start.
5 6 7 |
# File 'lib/zomato/restaurant.rb', line 5 def results_start @results_start end |
Instance Method Details
#attributes ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/zomato/restaurant.rb', line 39 def attributes { :results_found => @results_found, :results_start => @results_start, :results_shown => @results_shown, :resturants => @restaurants, :query => @query } end |
#first ⇒ Object
49 |
# File 'lib/zomato/restaurant.rb', line 49 def first; restaurants.first end |
#has_next_page? ⇒ Boolean
31 32 33 |
# File 'lib/zomato/restaurant.rb', line 31 def has_next_page? next_page_result_start <= results_found.to_i end |
#has_previous_page? ⇒ Boolean
35 36 37 |
# File 'lib/zomato/restaurant.rb', line 35 def has_previous_page? previous_page_result_start >= 0 end |
#last ⇒ Object
50 |
# File 'lib/zomato/restaurant.rb', line 50 def last; restaurants.last end |
#next_page! ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/zomato/restaurant.rb', line 15 def next_page! return self unless has_next_page? @results_start = next_page_result_start @query.merge({:start => results_start, :count => results_shown}) response = Api.get('/search', :query => @query).parsed_response load(response, @query) end |
#previous_page! ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/zomato/restaurant.rb', line 23 def previous_page! return self unless has_previous_page? @results_start = previous_page_result_start @query.merge({:start => results_start, :count => results_shown}) response = Api.get('/search', :query => query).parsed_response load(response, @query) end |
#total_pages ⇒ Object
11 12 13 |
# File 'lib/zomato/restaurant.rb', line 11 def total_pages (results_found.to_i / results_shown.to_f).ceil end |