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..db2b5a8d2 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.13.1) + coderay (~> 1.1) + method_source (~> 1.0) rack (2.0.6) 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 e69de29bb..4bad6a44d 100644 --- a/app/application.rb +++ b/app/application.rb @@ -0,0 +1,29 @@ +require 'pry' + +class Application + + @@items = [] + + def call(env) + resp = Rack::Response.new + req = Rack::Request.new(env) + + if req.path.match(/items/) + item = req.path.split("/items/").last + item_detail = @@items.find do |i| i.name == item + end + if item_detail + resp.write item_detail.price + else + resp.status = 400 + resp.write "Item not found" + 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..633fe0bd1 100644 --- a/app/item.rb +++ b/app/item.rb @@ -1,8 +1,11 @@ class Item attr_accessor :name, :price + @@items = [] + def initialize(name,price) @name = name @price = price + @@items << self end end