diff --git a/app/application.rb b/app/application.rb index 7e25e25c7..920e97a37 100644 --- a/app/application.rb +++ b/app/application.rb @@ -2,6 +2,8 @@ class Application @@items = ["Apples","Carrots","Pears"] + @@cart = [] + def call(env) resp = Rack::Response.new req = Rack::Request.new(env) @@ -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(/add/) + add_item = req.params["item"] + if @@items.include?(add_item) + @@cart << add_item + resp.write "added "+"#{add_item}" + else + resp.write "We don't have that item" + end + elsif req.path.match(/cart/) + if @@cart == [] + resp.write "Your cart is empty" + else + @@cart.each do |item| + resp.write "#{item}\n" + end + end else resp.write "Path Not Found" end