Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sara Nilsen - Space #35

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for rdebug-ide",
"type": "Ruby",
"request": "attach",
"remoteHost": "127.0.0.1",
"remotePort": "1234",
"remoteWorkspaceRoot": "${workspaceRoot}"
}
]
}
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ This project is both a culmination of our Intro to Ruby unit and our first stage

**It is expected that you will not be able to complete all requirements.** The three waves are organized by difficulty and relevance to the learning goals, and should be tackled in order.

### Hints

We have included some [optional design scaffolding](https://github.com/AdaGold/hotel/blob/design-scaffolding/design-scaffolding-notes.md) for this project, to help you get started if you don't know where to start, or to provide inspiration if you're a little stuck. Any student should feel free to use this scaffolding in whatever way is most helpful to them. However, **we recommend that you spend at least 1 full day thinking about design before reaching for this scaffolding**, to get practice thinking about this type of problem independently.

## Getting Started

We will use the same project structure we used for the previous project. Library code (such as classes) should be in files in the `lib` folder, and tests should be in files in the `test` folder.
Expand Down Expand Up @@ -103,7 +99,7 @@ Spend **no more than 1 hour** answering those questions and adjusting your proje

## Functional Requirements

### Wave One: Tracking Reservations
### Wave 1: Tracking Reservations

In this wave, write the functionality for the system to track valid reservations, so that a user of the hotel system can make and find valid bookings for their hotel.

Expand Down Expand Up @@ -145,7 +141,7 @@ Remember: Your job is to only build the classes that store information and handl

</details>

### Wave Two: Room Availability
### Wave 2: Room Availability

#### User Stories

Expand All @@ -158,7 +154,7 @@ Remember: Your job is to only build the classes that store information and handl

- A reservation is allowed start on the same day that another reservation for the same room ends

### Wave Three: Hotel Blocks
### Wave 3: Hotel Blocks

If you are not familiar with what a block of hotel rooms, here is a brief description:

Expand Down
6 changes: 3 additions & 3 deletions feedback.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ reserves a room from a block | ✔️

| Overall Feedback | Criteria | yes/no |
| --- | --- | --- |
| Green (Meets/Exceeds Standards) | 14+ total in all sections | ✔️
| Yellow (Approaches Standards) | 9-13 total in all sections | ✔️
| Red (Not at Standard) | 0-8 total in all sections, or assignment is breaking/doesn’t run with less than 5 minutes of debugging | ✔️
| Green (Meets/Exceeds Standards) | 14+ total in all sections |
| Yellow (Approaches Standards) | 9-13 total in all sections |
| Red (Not at Standard) | 0-8 total in all sections, or assignment is breaking/doesn’t run with less than 5 minutes of debugging |

### Additional Feedback

Expand Down
31 changes: 31 additions & 0 deletions lib/date_range.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require_relative 'hotel_controller'
require 'date'

module Hotel
class DateRange
attr_accessor :start_date, :end_date

def initialize(start_date, end_date)
@start_date = start_date
@end_date = end_date
raise ArgumentError.new("date range is incorrect") if @start_date > @end_date || @start_date == @end_date
end

def overlap?(second_date_range)
if second_date_range.start_date >= @end_date || second_date_range.end_date <= @start_date
return false
else
return true
end
end

def include_date_range?(date_range)
date_range.start_date.between?(@start_date, @end_date) || date_range.end_date.between?(@start_date, @end_date)
end

def nights
return (@end_date - @start_date).to_i
end

end
end
59 changes: 59 additions & 0 deletions lib/hotel_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require_relative 'reservation'
require_relative 'room'
require_relative 'date_range'

module Hotel
class HotelController
attr_reader :rooms, :get_available_rooms, :access_reservations
attr_accessor :reserve_room
def initialize
@rooms = Array.new(20) { |i| Room.new(i + 1) }
@hotel_reservations = []

end

def reserve_room(room_to_reserve, date_range, hotel_block = :no)
if !room_to_reserve.check_availability(date_range)
raise ArgumentError.new("This room is not available")
else
new_reservation = Reservation.new(date_range, room_to_reserve, hotel_block)
room_to_reserve.add_reservation(new_reservation)
@hotel_reservations << new_reservation
return new_reservation
end
end

def get_available_rooms(date_range)
rooms_available = []
@rooms.each do |room|
if room.check_availability(date_range)
rooms_available << room
end
end
return rooms_available
end

def access_reservations(date_range)
list_reservations = []

@hotel_reservations.each do |r|
if r.date_range.include_date_range?(date_range)
list_reservations << r
end
end
return list_reservations
end

def reserve_block(date_range, rooms_to_reserve)
raise ArgumentError if !(3..5).include?(rooms_to_reserve.length)
rooms_to_reserve.each do |room|
begin
self.reserve_room(room, date_range, :yes)
rescue => exception
puts "Unable to reserve block: #{exception}"
end
end
end

end
end
29 changes: 29 additions & 0 deletions lib/reservation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'date'
require_relative 'date_range'

module Hotel
class Reservation
attr_reader :date_range, :room, :price, :cost, :hotel_block
def initialize(date_range, room, price = 200, hotel_block = :no)
@date_range = date_range
@room = room
@price = price
@hotel_block = hotel_block

if @hotel_block == :yes
@price = 180
end

valid_block = [:yes, :no]
raise ArgumentError if !valid_block.include?(@hotel_block)
end

def cost
total_cost = @date_range.nights * @price
return total_cost
end

end
end


29 changes: 29 additions & 0 deletions lib/room.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require_relative 'reservation'
require_relative 'date_range'

module Hotel
class Room
attr_reader :id, :reservations

def initialize(id, reservations = [])
@id = id
@reservations = []
end

def check_availability(date_range) # is available? #giving a date range to room and check if room is available for that day
@reservations.each do |r|
if r.date_range.overlap?(date_range)
return false
end
end
return true
end

def add_reservation(reservation)
@reservations << reservation
end
end
end



4 changes: 4 additions & 0 deletions refactors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
One thing i would do differently would be to create a class for hotel blocks.
I found myself lost multiple times for not having a specific space for creating the blocks.
I would want to find a better method name for access_reservations, could not come up with a more clear name that
indicate the function.
136 changes: 136 additions & 0 deletions test/date_range_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
require_relative "test_helper"

describe Hotel::DateRange do
describe "constructor" do
before do
start_date = Date.new(2017, 01, 01)
end_date = start_date + 3

@range = Hotel::DateRange.new(start_date, end_date)
end

it "Can be initialized with two dates" do
start_date = Date.new(2017, 01, 01)
end_date = start_date + 3
expect(@range.start_date).must_equal start_date
expect(@range.end_date).must_equal end_date
end

it "is an an error for negative-lenght ranges" do
start_date = Date.today
end_date = start_date - 3
expect { Hotel::DateRange.new(start_date, end_date) }.must_raise ArgumentError
end

it "is an error to create a 0-length range" do
start_date = Date.today
end_date = @start_date
expect { Hotel::DateRange.new(start_date, end_date) }.must_raise ArgumentError
end
end

describe "overlap?" do
before do
start_date = Date.new(2017, 01, 01)
end_date = start_date + 10

@range = Hotel::DateRange.new(start_date, end_date)
end

it "returns true for the same range" do
start_date = @range.start_date
end_date = @range.end_date
test_range = Hotel::DateRange.new(start_date, end_date)

expect(@range.overlap?(test_range)).must_equal true
end

it "returns true for a contained range" do
start_date = Date.new(2017, 01, 03)
end_date = start_date + 3
second_range = Hotel::DateRange.new(start_date, end_date)
expect(@range.overlap?(second_range)).must_equal true

end

it "returns true for a range that overlaps in front" do
start_date = Date.new(2016, 12, 27)
end_date = @range.start_date + 1 #end of the first range should be available for second_range night
second_range = Hotel::DateRange.new(start_date, end_date)
expect(@range.overlap?(second_range)).must_equal true
end

it "returns true for a range that overlaps in the back" do
start_date = @range.start_date
end_date = start_date + 4
second_range = Hotel::DateRange.new(start_date, end_date)
expect(@range.overlap?(second_range)).must_equal true
end

it "returns true for a containing range" do
start_date = @range.start_date - 4
end_date = @range.end_date + 3
second_range = Hotel::DateRange.new(start_date, end_date)
expect(@range.overlap?(second_range)).must_equal true
end

it "returns false for a range starting on the end_date date" do
start_date = @range.end_date
end_date = start_date + 3
second_range = Hotel::DateRange.new(start_date, end_date)
expect(@range.overlap?(second_range)).must_equal false
end

it "returns false for a range ending on the start_date date" do
start_date = Date.new(2016, 12, 27)
end_date = @range.start_date
second_range = Hotel::DateRange.new(start_date, end_date)
expect(@range.overlap?(second_range)).must_equal false
end

it "returns false for a range completely before" do
start_date = Date.new(2016, 12, 20)
end_date = start_date + 5
second_range = Hotel::DateRange.new(start_date, end_date)
expect(@range.overlap?(second_range)).must_equal false
end

it "returns false for a date completely after" do
start_date = Date.new(2017, 02, 03)
end_date = start_date + 5
second_range = Hotel::DateRange.new(start_date, end_date)
expect(@range.overlap?(second_range)).must_equal false
end
end

describe "nights" do
it "returns the correct number of nights" do
start_date = Date.new(2017, 02, 03)
end_date = start_date + 3
range = Hotel::DateRange.new(start_date, end_date)
expect(range.nights).must_equal 3

end
end
describe "include_date_range?" do
before do
start_date = Date.new(2017, 01, 01)
end_date = start_date + 3
@range = Hotel::DateRange.new(start_date, end_date)
end
it "is included in the range" do
second_start_date = Date.new(2017, 01, 01)
second_end_date = second_start_date + 1
second_range= Hotel::DateRange.new(second_start_date, second_end_date)
expect(@range.include_date_range?(second_range)).must_equal true
end
it "is not included in the range" do
start_date = Date.new(2016, 12, 27)
end_date = start_date + 2
second_range = Hotel::DateRange.new(start_date, end_date)
expect(@range.include_date_range?(second_range)).must_equal false
end
end


end
Loading