From 792b952bbf8b511c435acf6a9f04142041fd4fad Mon Sep 17 00:00:00 2001 From: Shreemangal Sethi Date: Thu, 18 Mar 2021 01:05:04 +0000 Subject: [PATCH] Done. --- app/application.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/application.rb b/app/application.rb index 7e25e25c7..fdc7392f6 100644 --- a/app/application.rb +++ b/app/application.rb @@ -1,6 +1,8 @@ class Application @@items = ["Apples","Carrots","Pears"] + + @@cart = [] def call(env) resp = Rack::Response.new @@ -13,6 +15,22 @@ def call(env) elsif req.path.match(/search/) search_term = req.params["q"] resp.write handle_search(search_term) + elsif req.path.match(/cart/) + if @@cart.empty? + resp.write "Your cart is empty" + else + @@cart.each do |item| + resp.write "#{item}\n" + end + end + elsif req.path.match(/add/) + search_term = req.params["item"] + if @@items.include?(search_term) + @@cart << search_term + resp.write "added #{search_term}" + else + resp.write "We don't have that item" + end else resp.write "Path Not Found" end