diff --git a/Gemfile b/Gemfile index 65300a9b1..9152e7c47 100644 --- a/Gemfile +++ b/Gemfile @@ -3,3 +3,4 @@ source 'https://rubygems.org' gem 'rack' gem 'rack-test' gem 'rspec' +gem 'pry' diff --git a/Gemfile.lock b/Gemfile.lock index 1f52c27d9..2f38e61bb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,12 @@ GEM remote: https://rubygems.org/ specs: + coderay (1.1.3) diff-lcs (1.3) + method_source (1.0.0) + pry (0.14.0) + coderay (~> 1.1) + method_source (~> 1.0) rack (2.0.6) rack-test (1.1.0) rack (>= 1.0, < 3) @@ -23,9 +28,10 @@ PLATFORMS ruby DEPENDENCIES + pry rack rack-test rspec BUNDLED WITH - 2.0.1 + 2.2.14 diff --git a/app/application.rb b/app/application.rb index e69de29bb..72d0d9aa3 100644 --- a/app/application.rb +++ b/app/application.rb @@ -0,0 +1,57 @@ +require 'pry' + +class Application + + @@items = [Item.new("Figs",3.42),Item.new("Pears",0.99)] + + def call(env) + resp = Rack::Response.new + req = Rack::Request.new(env) + + # if req.path.match(/testing/) + # if req.path=="/testing" + + if req.path.match(/items/) + item_name = req.path.split("/items/").last + found_item = @@items.find do |item| + item.name == item_name + end + if found_item + resp.write found_item.price + else + resp.write "Item not found" + resp.status = 400 + end + # binding.pry + else + # !@@item.include?(@@item.last) + resp.write "Route not found" + resp.status = 404 + end + resp.finish + end +end + +# elsif req.path.match(/items/) +# search_term = req.params["item"] +# if @@item.include?(search_term) +# @@item.each do |item| +# resp.write "#{item}\n" +# end +# else +# # elsif @@item.include?(@@item.last) +# resp.write "Item not found" +# resp.status = 404 +# end +# end + +# elsif req.path.match(/items/) + # if @@item.include?(@@item.last) + # @@item.each do |item| + # resp.write "#{item}\n" + # end + # else + # # !@@item.include?(@@item.last) + # resp.write "Item not found" + # resp.status = 404 + # end \ No newline at end of file