Skip to content
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
22 changes: 22 additions & 0 deletions lib/manager.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@


require_relative "reservation"
require_relative "room"

class Manager
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class seems pretty small for a "Manager" class which coordinates the reservations etc. I would also expect that it would have a list of reservations.

attr_reader :rooms

def initialize
@rooms = rooms
end

def make_rooms
@rooms = (1..20).to_a.map! do |room|
Room.new(id: room)
end
end

def all_reservations
@reservations << book_reservation(vacant_room, check_in, check_out)
end
end
35 changes: 35 additions & 0 deletions lib/reservation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class Reservation
attr_reader :room_num, :check_in, :check_out, :rate, :rooms

def initialize(room_num:, check_in:, check_out:, rooms:)
@room_num = available_room(rooms)
@rate = 200
@check_in = Date.parse(check_in)

@check_out = Date.parse(check_out)
if !@check_out.nil? && @check_out < @check_in
raise ArgumentError.new("Check-out date before check-in date")
end
@reservations = []
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would a Reservation class have a list of reservations?

end

def available_room(rooms)
vacant_room = rooms.find_index do |room|
next if !room.dates.empty?
else
return room #compare dates or choose empty? room
end
# # take the first available room and assign it.
# # add to the bookings array.
return vacant_room
end

def book_reservation(vacant_room, check_in, check_out)
end

def total_cost
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

duration = (check_out - check_in).to_i
total_cost = duration * @rate
return total_cost
end
end
9 changes: 9 additions & 0 deletions lib/room.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

class Room
attr_reader :id, :reservation, :rooms, :dates

def initialize(id:)
@id = id
@dates = []
end
end
32 changes: 32 additions & 0 deletions spec/manager_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require_relative "spec_helper"
describe "Manager Class" do
before do
room_num = 5
check_in = Date.parse("2019-05-14")
check_out = Date.parse("2019-05-18")
rooms = []
rooms << Room.new(id: 1)
rooms << Room.new(id: 2)
rooms << Room.new(id: 3)

@reservation1_data = {
room_num: 5,
check_in: check_in.to_s,
check_out: check_out.to_s,
rooms: rooms,

}
@reservation2_data = {
room_num: 7,
check_in: Date.parse("2019-06-02").to_s,
check_out: Date.parse("2019-06-04").to_s,
rooms: rooms,
}
@reservation1 = Reservation.new(@reservation1_data)
@reservation2 = Reservation.new(@reservation2_data)
@manager = Manager.new
end
it "is an instance of Manager" do
expect(@manager).must_be_kind_of Manager
end
end
43 changes: 43 additions & 0 deletions spec/reservation_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require_relative "spec_helper"
describe "Reservation Class" do
describe "initialize" do
before do
room_num = 5
check_in = Date.parse("2019-05-14")
check_out = Date.parse("2019-05-18")
rate = 200
rooms = []
rooms << Room.new(id: 1)
rooms << Room.new(id: 2)
rooms << Room.new(id: 3)

@reservation_data = {
room_num: 5,
check_in: check_in.to_s,
check_out: check_out.to_s,
rooms: rooms,

}
@reservation = Reservation.new(@reservation_data)
end

it "has a check-out date that is after the check-in date." do
expect(@reservation.check_out > @reservation.check_in).must_equal true
end

it "throws ArgumentError when check-out date is before the check-in date." do
expect do
Reservation.new(room_num: 7, check_in: "2019-05-14", check_out: "2019-05-13", rate: 200)
end.must_raise ArgumentError
end

it "is an instance of Reservation" do
expect(@reservation).must_be_kind_of Reservation
end

it "calculates the total cost of the stay" do
expect(@reservation.total_cost).must_equal 800
puts "This reservation will cost $#{@reservation.total_cost}."
end
end
end
14 changes: 14 additions & 0 deletions spec/room_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require_relative "spec_helper"

describe "Room Class" do
describe "Room initializer" do
before do
@room = Room.new(
id: 1,
)
end
it "is an instance of Room" do
expect(@room).must_be_kind_of Room
end
end
end
14 changes: 9 additions & 5 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Add simplecov
require 'minitest'
require 'minitest/autorun'
require 'minitest/reporters'
require "simplecov"
SimpleCov.start
require "date"
require "minitest"
require "minitest/autorun"
require "minitest/reporters"

Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new

# Require_relative your lib files here!
require_relative "../lib/manager"
require_relative "../lib/reservation"
require_relative "../lib/room"