From d25cd0f44811c9d2c1a6a066a851450503ff77c8 Mon Sep 17 00:00:00 2001 From: Neil Ryan Date: Wed, 29 Apr 2020 22:41:58 -0700 Subject: [PATCH] Completed lab --- app/application.rb | 24 ++++++++++++++++++++++++ app/item.rb | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/application.rb b/app/application.rb index e69de29bb..bee15064b 100644 --- a/app/application.rb +++ b/app/application.rb @@ -0,0 +1,24 @@ +class Application + + 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 diff --git a/app/item.rb b/app/item.rb index f9107bf2f..97ab9240a 100644 --- a/app/item.rb +++ b/app/item.rb @@ -1,8 +1,9 @@ class Item attr_accessor :name, :price - + def initialize(name,price) @name = name @price = price end + end