From 12653f6f48f1d82487e5608d46ad651a7095e210 Mon Sep 17 00:00:00 2001 From: Hannah-Dagemark Date: Mon, 4 Dec 2023 10:19:08 +0100 Subject: [PATCH] Added Route file and class --- lib/route.rb | 21 +++++++++++++++++++++ testing.rb => testing_requests.rb | 0 testing_routes.rb | 10 ++++++++++ 3 files changed, 31 insertions(+) rename testing.rb => testing_requests.rb (100%) create mode 100644 testing_routes.rb diff --git a/lib/route.rb b/lib/route.rb index e69de29..be5bee4 100644 --- a/lib/route.rb +++ b/lib/route.rb @@ -0,0 +1,21 @@ +class Route + attr_reader :routes + def initialize() + @routes = {} + end + + def add_route(input) + @routes.merge!(input) + p "added successfully, @routes are: #{@routes}" + end + + def match_route(input) + resource = input.resource + if @routes[resource] + return @routes[resource] + else + p "failed to find: #{resource} route" + end + end + +end \ No newline at end of file diff --git a/testing.rb b/testing_requests.rb similarity index 100% rename from testing.rb rename to testing_requests.rb diff --git a/testing_routes.rb b/testing_routes.rb new file mode 100644 index 0000000..7ca6a4c --- /dev/null +++ b/testing_routes.rb @@ -0,0 +1,10 @@ +require_relative 'lib/route' +require_relative 'lib/request' + +request_string = File.read('spec/example_requests/get-examples.request.txt') +route = Route.new +request = Request.new(request_string) + +examples = {"/nopers" => "okidoki"} +route.add_route(examples) +p route.match_route(request) \ No newline at end of file