diff --git a/Sandwich/menu.csv b/Sandwich/menu.csv index b3053bd..aa47f4d 100644 --- a/Sandwich/menu.csv +++ b/Sandwich/menu.csv @@ -1,7 +1,7 @@ "id","name","description","price" "1","Smoked Salmon Sandwich","Atlantic smoked salmon with cream cheese, cucumber, tomatoes, red onions and capers on a Telera roll","7.95" -"2","Pan Bagnat Sanwich","Tuna salad topped with iceberg lettuce, tomatoes, red bell peppers, cucumber, olive tapenade, boiled egg and fresno chilies on a multigrain hero roll","8.95" -"3","Over Roasted Turkey Sandwich","Diestel Farms oven roasted turkey breast with chipotle aioli, iceberg lettuce, tomatoes, avocado, bacon, and pepper jack cheese on an Italian country roll","8.95" +"2","Pan Bagnat Sandwich","Tuna salad topped with iceberg lettuce, tomatoes, red bell peppers, cucumber, olive tapenade, boiled egg and fresno chilies on a multigrain hero roll","8.95" +"3","Oven Roasted Turkey Sandwich","Diestel Farms oven roasted turkey breast with chipotle aioli, iceberg lettuce, tomatoes, avocado, bacon, and pepper jack cheese on an Italian country roll","8.95" "4","Baltimore Beef Sandwich","Roast beef with horseradish cream, pickled red onions, tomatoes and swiss cheese on a Poppy seed roll","8.95" "5","Pastrami Sandiwch","Pastrami with cole slaw, pepperoncini and russian dressing on a country Italian roll","8.95" "6","Bacon Cobb Sandwich","The classic BLT with avocado vrema, boiled egg and topped with crumbled blue cheese on a Telera roll","8.95" diff --git a/Sandwich/sandwich.rb b/Sandwich/sandwich.rb index 344bfec..a9256be 100644 --- a/Sandwich/sandwich.rb +++ b/Sandwich/sandwich.rb @@ -1,4 +1,6 @@ require 'csv' +require 'rubygems' +require 'twilio-ruby' class Sandwich attr_reader :id, :price, :name, :description @@ -12,20 +14,149 @@ def initialize(args = {}) class Controller - attr_reader :sandwich_list + attr_reader :sandwich_list, :twilio_message def initialize @sandwich_list = [] @view=View.new CSV.foreach('menu.csv', headers: true, header_converters: :symbol) do |row| @sandwich_list << Sandwich.new(row) end + @exit = false + @cart = [] + @twilio_message = "" end + + def drive + display_menu + while @exit != true + options + decision + end + end + def display_menu - @view.render_menu(sandwich_list) + @view.render_menu(@sandwich_list) + end + + def display_cart_remove + @view.render("YOUR CART") + @cart.each do |sandwich| + @view.render("#{sandwich.id} #{sandwich.name} #{sandwich.price}") + end + end + + def display_cart + @view.render("YOUR CART") + @cart.each do |sandwich| + @view.render(" - #{sandwich.name} #{sandwich.price}") + end + @view.render("Total: #{sum}") end + + def sum + sum = 0 + @cart.each do |sandwich| + sum += sandwich.price.to_f + end + sum.round(2) + end + def request_order @view.render_order(sandwich_list) end + + def options + @view.render_options + end + + def add_sandwich + @view.render_menu(sandwich_list) + sandwich_name = @view.render_order(sandwich_list) + @sandwich_list.each do |sandwich| + if sandwich.name == sandwich_name + @cart << sandwich + end + end + end + + def remove_sandwich + target = "" + display_cart_remove + @view.render("What number sandwich would you like to remove?") + sandwich_id = gets.chomp + @cart.each do |sandwich| + if sandwich.id == sandwich_id + target = sandwich + end + end + @cart.delete_at(@cart.find_index(target)) + end + + def prepare_order + sandwich_cart_hash = {} + @cart.each do |sandwich| + if sandwich_cart_hash.has_key?(sandwich.name) + sandwich_cart_hash[sandwich.name] += 1 + else + sandwich_cart_hash[sandwich.name] = 1 + end + end + sandwich_cart_hash + end + + def place_order + sandwich_cart_hash = prepare_order + sandwich_cart_hash.each do |k,v| + @twilio_message += "\n#{v}: #{k}" + end + @twilio_message + end + + def twilio_message + account_sid = "AC27bf9c7c50adfe10a7c0e4660e3e61cd" + auth_token = "02ecd2a115226c4d817297984e3d1a05" + client = Twilio::REST::Client.new account_sid, auth_token + from = "+16506845053" + + friends = { + "+16505801483" => "Julian", + "+17034709608" => "Kevin", + ## Store owner will add more customers/friends here + # # "+16506363688" => "Henry", + #"+19098019741" => "Ryan" + } + unless @twilio_message.empty? + friends.each do |key, value| + client.account.messages.create( + :from => from, + :to => key, + :body => @twilio_message + ) + puts "Sent message to #{value}" + end + end + @view.render("You must place a sandwich in your cart") if @twilio_message.empty? + end + + def decision + choice = gets.chomp.downcase + case choice + when 'add' + add_sandwich + when 'exit','end' + @exit = true + when 'm','menu' + display_menu + when 'r','remove' + remove_sandwich + when 's','show' + display_cart + when 'o','order' + place_order + twilio_message + end + end + end class View @@ -44,11 +175,25 @@ def render_order(sandwich_list) sandwich_order = gets.chomp.to_i sandwich_name = sandwich_list[sandwich_order - 1].name puts "You selected #{sandwich_name}" + return sandwich_name + end + def render_options + puts + puts '-'*100 + puts + puts "Enter one of the following commands to perform blsdf" + puts "'Add' - to add another sandwich to the list" + puts "'Remove' - to remove a sandwich fromt the list" + puts "'Show' - to show all the sandwiches in the cart" + puts "'Order' - to place the order" + puts "'Exit' - to place the exit" + end + def render(customized_message) + puts "#{customized_message}" end end -while - menu = Controller.new -menu.display_menu -menu.request_order +menu.drive + +