Class: HungryVegan::Restaurant

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRestaurant

Returns a new instance of Restaurant.



9
10
11
# File 'lib/hungry_vegan/restaurant.rb', line 9

def initialize
    
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



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

def address
  @address
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#matching_zip_codesObject

Returns the value of attribute matching_zip_codes.



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

def matching_zip_codes
  @matching_zip_codes
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#phone_numberObject

Returns the value of attribute phone_number.



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

def phone_number
  @phone_number
end

#ratingObject

Returns the value of attribute rating.



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

def rating
  @rating
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

#zipObject

Returns the value of attribute zip.



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

def zip
  @zip
end

Class Method Details

.allObject



13
14
15
# File 'lib/hungry_vegan/restaurant.rb', line 13

def self.all
    @@all
end

.create(hash, zip) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/hungry_vegan/restaurant.rb', line 23

def self.create(hash, zip)
    restaurant = Restaurant.new 
    restaurant.id=hash["id"]
    restaurant.name=hash["name"]
    restaurant.rating=hash["rating"]
    restaurant.phone_number=hash["display_phone"]
    restaurant.url=hash["url"]
    restaurant.matching_zip_codes= [zip]
    self.all<<restaurant
    restaurant
end

.find_or_create(attributes_hash, zip) ⇒ Object



17
18
19
20
21
# File 'lib/hungry_vegan/restaurant.rb', line 17

def self.find_or_create(attributes_hash, zip)
    restaurant= self.all.find {|object| object.id ==attributes_hash["id"]}||self.create(attributes_hash, zip)
    restaurant.matching_zip_codes<<zip unless restaurant.matching_zip_codes.include?(zip)
    restaurant
end

.get_matching_restaurats(zip) ⇒ Object



44
45
46
# File 'lib/hungry_vegan/restaurant.rb', line 44

def self.get_matching_restaurats(zip)
    self.all.select{|r|r.matching_zip_codes.include?(zip)}
end

.get_restaurants_from_zip(zip) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/hungry_vegan/restaurant.rb', line 35

def self.get_restaurants_from_zip(zip)
    businesses= Api.search(term="vegan", zip) ["businesses"]
    businesses.collect do |business|
        if business.class== Hash
            Restaurant.find_or_create(business, zip)
        end
    end 
end