From c03e0e0c83364ba0cf8623d0476ee8d694066e3b Mon Sep 17 00:00:00 2001 From: Jonathan Fernandez Date: Thu, 5 Dec 2019 01:14:37 +0000 Subject: [PATCH] Done. --- app/application.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/application.rb b/app/application.rb index e69de29bb..6cac6d726 100644 --- a/app/application.rb +++ b/app/application.rb @@ -0,0 +1,26 @@ +class Application + + @@items = [] + + + def call(env) + req = Rack::Request.new(env) + resp = Rack::Response.new + + if req.path.match(/items\/.+/) + item_name = req.path.split("/items/").last + item = @@items.detect { |i| i.name == item_name } + if item + resp.write item.price + else + resp.write "Item not found" + resp.status = 400 + end + else + resp.write "Route not found" + resp.status = 404 + end + + resp.finish + end +end \ No newline at end of file