Class: HungryVegan::Restaurant
- Inherits:
-
Object
- Object
- HungryVegan::Restaurant
- Defined in:
- lib/hungry_vegan/restaurant.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#id ⇒ Object
Returns the value of attribute id.
-
#matching_zip_codes ⇒ Object
Returns the value of attribute matching_zip_codes.
-
#name ⇒ Object
Returns the value of attribute name.
-
#phone_number ⇒ Object
Returns the value of attribute phone_number.
-
#rating ⇒ Object
Returns the value of attribute rating.
-
#url ⇒ Object
Returns the value of attribute url.
-
#zip ⇒ Object
Returns the value of attribute zip.
Class Method Summary collapse
- .all ⇒ Object
- .create(hash, zip) ⇒ Object
- .find_or_create(attributes_hash, zip) ⇒ Object
- .get_matching_restaurats(zip) ⇒ Object
- .get_restaurants_from_zip(zip) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Restaurant
constructor
A new instance of Restaurant.
Constructor Details
#initialize ⇒ Restaurant
Returns a new instance of Restaurant.
9 10 11 |
# File 'lib/hungry_vegan/restaurant.rb', line 9 def initialize end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
5 6 7 |
# File 'lib/hungry_vegan/restaurant.rb', line 5 def address @address end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/hungry_vegan/restaurant.rb', line 5 def id @id end |
#matching_zip_codes ⇒ Object
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 |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/hungry_vegan/restaurant.rb', line 5 def name @name end |
#phone_number ⇒ Object
Returns the value of attribute phone_number.
5 6 7 |
# File 'lib/hungry_vegan/restaurant.rb', line 5 def phone_number @phone_number end |
#rating ⇒ Object
Returns the value of attribute rating.
5 6 7 |
# File 'lib/hungry_vegan/restaurant.rb', line 5 def @rating end |
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/hungry_vegan/restaurant.rb', line 5 def url @url end |
#zip ⇒ Object
Returns the value of attribute zip.
5 6 7 |
# File 'lib/hungry_vegan/restaurant.rb', line 5 def zip @zip end |
Class Method Details
.all ⇒ Object
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.=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 |