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..21d506f73 100644 --- a/app/application.rb +++ b/app/application.rb @@ -1,11 +1,13 @@ class Application + + @@items = ["Apples","Carrots","Pears"] - @@items = ["Apples","Carrots","Pears"] + @@cart = [] - 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 +15,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 +43,4 @@ def handle_search(search_term) return "Couldn't find #{search_term}" end end -end +end \ No newline at end of file