From aefba37a5e2109a636712555b20bd0c63efe76a3 Mon Sep 17 00:00:00 2001 From: Olivia Kesler Date: Sun, 15 Dec 2019 02:14:17 +0000 Subject: [PATCH] Done. --- app/application.rb | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/app/application.rb b/app/application.rb index 7e25e25c7..3160bfc40 100644 --- a/app/application.rb +++ b/app/application.rb @@ -1,22 +1,40 @@ class Application @@items = ["Apples","Carrots","Pears"] + + @@cart = [ ] def call(env) resp = Rack::Response.new req = Rack::Request.new(env) - + if req.path.match(/items/) @@items.each do |item| resp.write "#{item}\n" end + elsif req.path.match(/search/) search_term = req.params["q"] resp.write handle_search(search_term) + + elsif req.path.match(/cart/) + if @@cart.length == 0 + resp.write "Your cart is empty" + else + resp.write "#{@@cart.join("\n")}" + end + + elsif req.path.match(/add/) + item = req.params["item"] + if @@items.include?(item) + @@cart << item + resp.write "added #{item}" + else + resp.write "We don't have that item" + end else resp.write "Path Not Found" end - resp.finish end @@ -27,4 +45,6 @@ def handle_search(search_term) return "Couldn't find #{search_term}" end end + + end