From 992b8344215ba4b45e220c216148d38dd72281d3 Mon Sep 17 00:00:00 2001 From: Vicky Tee Date: Thu, 8 Apr 2021 12:42:18 +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..45912eeb7 100644 --- a/app/application.rb +++ b/app/application.rb @@ -0,0 +1,26 @@ +class Application + + @@Items = [] + + def call(env) + resp = Rack::Response.new + req = Rack::Request.new(env) + + if req.path.match(/items/) + item_name = req.path.split("/items/").last + item = @@items.find{|i| i.name == item_name} + if item != nil + 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