Class: Controller
- Inherits:
-
Object
- Object
- Controller
- Defined in:
- lib/DinnerChoice/controllers/DinnerChoiceController.rb
Instance Method Summary collapse
- #create(results) ⇒ Object
- #delete_index(delete_index) ⇒ Object
- #dice ⇒ Object
- #index ⇒ Object
-
#initialize(restaurant_views, restaurant_repo) ⇒ Controller
constructor
A new instance of Controller.
- #menu_list ⇒ Object
- #new ⇒ Object
- #remove ⇒ Object
- #rewrite ⇒ Object
- #update_info(update_index, select_item, update_content) ⇒ Object
Constructor Details
#initialize(restaurant_views, restaurant_repo) ⇒ Controller
Returns a new instance of Controller.
8 9 10 11 |
# File 'lib/DinnerChoice/controllers/DinnerChoiceController.rb', line 8 def initialize(restaurant_views, restaurant_repo) @restaurant_views = restaurant_views @restaurant_repo = restaurant_repo end |
Instance Method Details
#create(results) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/DinnerChoice/controllers/DinnerChoiceController.rb', line 17 def create(results) name, address, , average_price = capitalize(results) count = @restaurant_repo.add(Restaurant.new(name, address, , average_price)) waiting() puts if count == 1 puts "New restaurant is successfully added!".colorize(:green) end end |
#delete_index(delete_index) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/DinnerChoice/controllers/DinnerChoiceController.rb', line 32 def delete_index(delete_index) count = @restaurant_repo.delete(delete_index) waiting() puts if count == -1 puts "The restaurant is successfully deleted!".colorize(:green) end end |
#dice ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/DinnerChoice/controllers/DinnerChoiceController.rb', line 85 def dice if @restaurant_repo.database == [] puts puts "List is empty...There is nothing to choose from!".colorize(:red) puts "Select 1 if you want to add a new entry." else puts waiting() sleep 0.5 print " ......".colorize(:green) sleep 0.5 print "Dice rolling".colorize(:green) sleep 0.5 puts "......".colorize(:green) sleep 0.5 waiting() selected_restaurant = roll_dice(@restaurant_repo.database) @restaurant_views.index(selected_restaurant) end end |
#index ⇒ Object
13 14 15 |
# File 'lib/DinnerChoice/controllers/DinnerChoiceController.rb', line 13 def index @restaurant_views.index(@restaurant_repo.database) end |
#menu_list ⇒ Object
81 82 83 |
# File 'lib/DinnerChoice/controllers/DinnerChoiceController.rb', line 81 def @restaurant_views. end |
#new ⇒ Object
27 28 29 30 |
# File 'lib/DinnerChoice/controllers/DinnerChoiceController.rb', line 27 def new results = @restaurant_views.new create(results) end |
#remove ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/DinnerChoice/controllers/DinnerChoiceController.rb', line 41 def remove if @restaurant_repo.database == [] puts puts "List is empty, nothing to delete.".colorize(:red) else remove_index = @restaurant_views.delete_command if (remove_index < 0) || (remove_index > (@restaurant_repo.database.count - 1)) () puts "Please select ID from the existing restaurants list." else delete_index(remove_index) end end end |
#rewrite ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/DinnerChoice/controllers/DinnerChoiceController.rb', line 63 def rewrite if @restaurant_repo.database == [] puts puts "List is empty, nothing to update.".colorize(:red) puts "Select 1 if you want to add a new entry." else update_index = @restaurant_views.update_index if (update_index < 0) || (update_index > (@restaurant_repo.database.count - 1)) () puts "Please select ID from the existing restaurants list." else update_array = @restaurant_views.update_command update_info(update_index, update_array[0], update_array[1]) end end end |
#update_info(update_index, select_item, update_content) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/DinnerChoice/controllers/DinnerChoiceController.rb', line 56 def update_info(update_index, select_item, update_content) @restaurant_repo.update(update_index, select_item, update_content) waiting() puts puts "The restaurant is successfully edited!".colorize(:green) end |