Class: Zomato::Restaurant::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/zomato/restaurant.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#restaurantsObject (readonly)

Returns the value of attribute restaurants.


5
6
7
# File 'lib/zomato/restaurant.rb', line 5

def restaurants
  @restaurants
end

#results_foundObject (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_shownObject (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_startObject (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

#attributesObject


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

#firstObject


49
# File 'lib/zomato/restaurant.rb', line 49

def first; restaurants.first end

#has_next_page?Boolean

Returns:

  • (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

Returns:

  • (Boolean)

35
36
37
# File 'lib/zomato/restaurant.rb', line 35

def has_previous_page?
  previous_page_result_start >= 0
end

#lastObject


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_pagesObject


11
12
13
# File 'lib/zomato/restaurant.rb', line 11

def total_pages
  (results_found.to_i / results_shown.to_f).ceil
end