Class: RestaurantRepository
- Inherits:
-
Object
- Object
- RestaurantRepository
- Defined in:
- lib/DinnerChoice/repositories/RestaurantRepository.rb
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
Returns the value of attribute database.
Instance Method Summary collapse
- #add(restaurant) ⇒ Object
- #delete(delete_input) ⇒ Object
-
#initialize ⇒ RestaurantRepository
constructor
A new instance of RestaurantRepository.
- #update(update_input, select_item, update_content) ⇒ Object
Constructor Details
#initialize ⇒ RestaurantRepository
Returns a new instance of RestaurantRepository.
5 6 7 8 9 10 |
# File 'lib/DinnerChoice/repositories/RestaurantRepository.rb', line 5 def initialize pappaRich = Restaurant.new('Pappa Rich', 'Southern cross station, L1-CS-03', '3.5', '9') hungryJacks = Restaurant.new('Hungry Jack\'s', 'Spencer Street', '2.5', '9.5') grilld = Restaurant.new('Grill\'d', 'Southern cross station', '4', '17') @database = [pappaRich, hungryJacks, grilld] end |
Instance Attribute Details
#database ⇒ Object (readonly)
Returns the value of attribute database.
4 5 6 |
# File 'lib/DinnerChoice/repositories/RestaurantRepository.rb', line 4 def database @database end |
Instance Method Details
#add(restaurant) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/DinnerChoice/repositories/RestaurantRepository.rb', line 12 def add(restaurant) length_brfore = @database.length @database << restaurant length_after = @database.length count = length_after - length_brfore return count end |
#delete(delete_input) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/DinnerChoice/repositories/RestaurantRepository.rb', line 20 def delete(delete_input) length_brfore = @database.length @database.delete_at(delete_input) length_after = @database.length count = length_after - length_brfore return count end |
#update(update_input, select_item, update_content) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/DinnerChoice/repositories/RestaurantRepository.rb', line 28 def update(update_input, select_item, update_content) update_restaurant = @database[update_input] case select_item when 'name' update_restaurant.name = update_content when 'address' update_restaurant.address = update_content when 'rating' update_restaurant. = update_content when 'price','average price' update_restaurant.average_price = update_content end end |