From 39dd53c6cb30c706f23383c4b3bf975cc0a9e005 Mon Sep 17 00:00:00 2001 From: Angeleen MCDONNELL Wilson Date: Fri, 3 Jul 2020 05:27:15 +0000 Subject: [PATCH 1/2] Done. --- Gemfile.lock | 6 ++++++ app/application.rb | 24 ++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index b25b7fa68..4f1f1ddc5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,12 @@ GEM remote: https://rubygems.org/ specs: + coderay (1.1.2) diff-lcs (1.3) + method_source (0.9.2) + pry (0.12.2) + coderay (~> 1.1.0) + method_source (~> 0.9.0) rack (2.0.8) rack-test (1.1.0) rack (>= 1.0, < 3) @@ -23,6 +28,7 @@ PLATFORMS ruby DEPENDENCIES + pry rack rack-test rspec diff --git a/app/application.rb b/app/application.rb index 7e25e25c7..c5e25f0e7 100644 --- a/app/application.rb +++ b/app/application.rb @@ -1,11 +1,9 @@ class Application - @@items = ["Apples","Carrots","Pears"] - def call(env) + 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" @@ -13,13 +11,27 @@ 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 - resp.finish end - def handle_search(search_term) if @@items.include?(search_term) return "#{search_term} is one of our items" @@ -27,4 +39,4 @@ def handle_search(search_term) return "Couldn't find #{search_term}" end end -end +end \ No newline at end of file From 0ebd2ecf2df7f3e39c1cabd060200d6c7d39beb1 Mon Sep 17 00:00:00 2001 From: Angeleen MCDONNELL Wilson Date: Fri, 3 Jul 2020 05:29:05 +0000 Subject: [PATCH 2/2] Done. --- app/application.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/application.rb b/app/application.rb index c5e25f0e7..21d506f73 100644 --- a/app/application.rb +++ b/app/application.rb @@ -1,4 +1,8 @@ class Application + + @@items = ["Apples","Carrots","Pears"] + + @@cart = [] def call(env)