Class: Zomato2::Restaurant

Inherits:
EntityBase show all
Defined in:
lib/zomato2/restaurant.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from EntityBase

#get

Constructor Details

#initialize(zom_conn, attributes) ⇒ Restaurant

Returns a new instance of Restaurant.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/zomato2/restaurant.rb', line 10

def initialize(zom_conn, attributes)
  super(zom_conn)
  @location = Location.new zom_conn, attributes["location"]
  @city_id = @location.city_id

  attributes.each do |k,v|
    if k == 'apikey'
      next
    elsif k == 'R'
      @id = v['res_id']
    # Zomato never returns this?? bad API doc!
    elsif k == 'location'
      next
    elsif k == 'all_reviews'
      @reviews = v.map{ |r| Review.new(zom_conn, r) }
    elsif k == 'establishment_types'
      @establishments = v.map{ |e,ev| Establishment.new(zom_conn, @city_id, ev) }
    # elsif k == 'cuisines' the returned cuisines here are just a string..
    else
      #puts "ATTR @#{k} val #{v}"
      self.instance_variable_set("@#{k}", v)
    end
  end
end

Instance Attribute Details

#all_reviews_countObject (readonly)

Returns the value of attribute all_reviews_count.



4
5
6
# File 'lib/zomato2/restaurant.rb', line 4

def all_reviews_count
  @all_reviews_count
end

#average_cost_for_twoObject (readonly)

Returns the value of attribute average_cost_for_two.



4
5
6
# File 'lib/zomato2/restaurant.rb', line 4

def average_cost_for_two
  @average_cost_for_two
end

#city_idObject (readonly)

Returns the value of attribute city_id.



4
5
6
# File 'lib/zomato2/restaurant.rb', line 4

def city_id
  @city_id
end

#cuisinesObject (readonly)

Returns the value of attribute cuisines.



4
5
6
# File 'lib/zomato2/restaurant.rb', line 4

def cuisines
  @cuisines
end

#currencyObject (readonly)

Returns the value of attribute currency.



4
5
6
# File 'lib/zomato2/restaurant.rb', line 4

def currency
  @currency
end

Returns the value of attribute deeplink.



4
5
6
# File 'lib/zomato2/restaurant.rb', line 4

def deeplink
  @deeplink
end

#establishmentsObject

Returns the value of attribute establishments.



8
9
10
# File 'lib/zomato2/restaurant.rb', line 8

def establishments
  @establishments
end

#events_urlObject (readonly)

Returns the value of attribute events_url.



4
5
6
# File 'lib/zomato2/restaurant.rb', line 4

def events_url
  @events_url
end

Returns the value of attribute featured_image.



4
5
6
# File 'lib/zomato2/restaurant.rb', line 4

def featured_image
  @featured_image
end

#has_online_deliveryObject (readonly)

Returns the value of attribute has_online_delivery.



4
5
6
# File 'lib/zomato2/restaurant.rb', line 4

def has_online_delivery
  @has_online_delivery
end

#has_table_bookingObject (readonly)

Returns the value of attribute has_table_booking.



4
5
6
# File 'lib/zomato2/restaurant.rb', line 4

def has_table_booking
  @has_table_booking
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/zomato2/restaurant.rb', line 4

def id
  @id
end

#is_delivering_nowObject (readonly)

Returns the value of attribute is_delivering_now.



4
5
6
# File 'lib/zomato2/restaurant.rb', line 4

def is_delivering_now
  @is_delivering_now
end

#locationObject (readonly)

Returns the value of attribute location.



4
5
6
# File 'lib/zomato2/restaurant.rb', line 4

def location
  @location
end

Returns the value of attribute menu_url.



4
5
6
# File 'lib/zomato2/restaurant.rb', line 4

def menu_url
  @menu_url
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/zomato2/restaurant.rb', line 4

def name
  @name
end

#phone_numbersObject (readonly)

Returns the value of attribute phone_numbers.



4
5
6
# File 'lib/zomato2/restaurant.rb', line 4

def phone_numbers
  @phone_numbers
end

#photo_countObject (readonly)

Returns the value of attribute photo_count.



4
5
6
# File 'lib/zomato2/restaurant.rb', line 4

def photo_count
  @photo_count
end

#photosObject (readonly)

Returns the value of attribute photos.



4
5
6
# File 'lib/zomato2/restaurant.rb', line 4

def photos
  @photos
end

#photos_urlObject (readonly)

Returns the value of attribute photos_url.



4
5
6
# File 'lib/zomato2/restaurant.rb', line 4

def photos_url
  @photos_url
end

#price_rangeObject (readonly)

Returns the value of attribute price_range.



4
5
6
# File 'lib/zomato2/restaurant.rb', line 4

def price_range
  @price_range
end

#reviewsObject

Returns the value of attribute reviews.



8
9
10
# File 'lib/zomato2/restaurant.rb', line 8

def reviews
  @reviews
end

#thumbObject (readonly)

Returns the value of attribute thumb.



4
5
6
# File 'lib/zomato2/restaurant.rb', line 4

def thumb
  @thumb
end

#user_ratingObject (readonly)

Returns the value of attribute user_rating.



4
5
6
# File 'lib/zomato2/restaurant.rb', line 4

def user_rating
  @user_rating
end

Instance Method Details

#<=>(other) ⇒ Object



41
42
43
# File 'lib/zomato2/restaurant.rb', line 41

def <=>(other)
  @id <=> other.id
end

#==(other) ⇒ Object



37
38
39
# File 'lib/zomato2/restaurant.rb', line 37

def ==(other)
  @id == other.id and @name == other.name and @city_id == other.city_id # ...
end

#details(start: nil, count: nil) ⇒ Object

this doesn’t actually give any more detailed info..



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/zomato2/restaurant.rb', line 55

def details(start: nil, count: nil)
# warn "\tRestaurant#details: This method is currently useless, since, " +
#      "as of January 2017, Zomato's API doesn't give any additional info here."

  q = {res_id: @id }
  q[:start] = start if start
  q[:count] = count if count
  results = get('restaurant', q)

  @location ||= Location.new zom_conn, attributes["location"]
  @city_id ||= @location.city_id

  results.each do |k,v|
    if k == 'apikey'
      next
    elsif k == 'R'
      @id = v['res_id']
    # Zomato never returns this?? bad API doc!
    elsif k == 'location'
      next
    elsif k == 'all_reviews'
      @reviews ||= v.map{ |r| Review.new(zom_conn, r) }
    elsif k == 'establishment_types'
      @establishments ||= v.map{ |e,ev| Establishment.new(zom_conn, @city_id, ev) }
    # elsif k == 'cuisines' the returned cuisines here are just a string..
    else
      #puts "ATTR @#{k} val #{v}"
      self.instance_variable_set("@#{k}", v)
    end
  end
  self
end


45
46
47
48
49
50
51
52
# File 'lib/zomato2/restaurant.rb', line 45

def menu(start: nil, count: nil)
  q = {res_id: @id }
  q[:start] = start if start
  q[:count] = count if count
  results = get('dailymenu', q)
  return nil if results['message'] == "No Daily Menu Available"
  results['daily_menu'].map { |e| Menu.new(@zom_conn, @id, e['daily_menu']) }
end

#to_sObject



35
# File 'lib/zomato2/restaurant.rb', line 35

def to_s; super; end