-
Notifications
You must be signed in to change notification settings - Fork 45
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
Amy Lee -- Carets #31
base: master
Are you sure you want to change the base?
Changes from 24 commits
681579e
86e2d67
09030e3
75897f5
b2cd5f1
9b1783a
531f35e
3638f06
100fffe
f60aab0
107fd3a
8d8ca89
b884efd
420fb74
5de0cd9
729b56f
b56ae49
57c76a9
f4a8494
3b43cc3
7aa52b8
35e687f
6e20e8c
ed4d23c
af12b8a
a4779d8
aa4b0dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'rake/testtask' | ||
|
||
Rake::TestTask.new do |t| | ||
t.libs = ["lib"] | ||
t.warning = false | ||
t.test_files = FileList['specs/*_spec.rb'] | ||
end | ||
|
||
task default: :test |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
module HotelBooking | ||
class Block | ||
attr_accessor :id, :guest, :check_in, :check_out, :room_ids | ||
attr_reader :discounted_rate | ||
|
||
def initialize(check_in,check_out,room_ids,discounted_rate,block_id) | ||
@check_in = check_in #ruby Date object | ||
@check_out = check_out #ruby Date object | ||
@room_ids = room_ids | ||
@discounted_rate = discounted_rate | ||
@id = block_id | ||
end | ||
|
||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require_relative 'Reservation' | ||
|
||
module HotelBooking | ||
class BlockReservation < HotelBooking::Reservation | ||
attr_accessor :id, :guest, :check_in, :check_out, :room, :block_id | ||
attr_reader :all_reservations, :type | ||
|
||
def initialize(check_in,check_out,room_id, b_res_id, block_discount, guest = nil) | ||
super(check_in,check_out,room_id, b_res_id,block_discount, guest = nil) | ||
@rate = block_discount | ||
@block_id = nil | ||
@type= :block | ||
end #end initialize | ||
|
||
def cost | ||
num_nights_charged * @rate | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
require 'date' | ||
require_relative 'Reservation' | ||
require_relative 'Room' | ||
require_relative 'Block' | ||
module HotelBooking | ||
|
||
class Hotel | ||
attr_reader :all_rooms, :all_reservations, :all_blocks | ||
NUM_STANDARD_ROOMS = 20 | ||
|
||
def initialize | ||
@all_rooms = HotelBooking::Hotel.setup_rooms | ||
@all_reservations = [] | ||
@all_blocks = [] | ||
end | ||
|
||
def available_rooms(check_in,check_out, block_id = nil) | ||
|
||
check_valid_dates(check_in,check_out) | ||
@all_rooms.select {|room| room.available_all_days?(check_in, check_out)} | ||
end | ||
|
||
def make_block(check_in,check_out,room_ids,discounted_rate) | ||
check_in_date = Date.parse(check_in) | ||
check_out_date = Date.parse(check_out) | ||
|
||
check_valid_dates(check_in_date,check_out_date) | ||
check_valid_block(check_in_date,check_out_date,room_ids) | ||
|
||
block_id = "B" + "#{@all_blocks.count + 1}" | ||
|
||
# block_rooms = [] | ||
# | ||
# room_ids.each do |id| | ||
# room = find_room_by_id(id) | ||
# block_rooms << room | ||
# end | ||
|
||
block = HotelBooking::Block.new(check_in_date,check_out_date,room_ids,discounted_rate,block_id) | ||
|
||
room_ids.each do |room_id| | ||
room= find_room_by_id(room_id) | ||
room.block_room(check_in_date,check_out_date,block_id) | ||
end | ||
|
||
@all_blocks << block | ||
|
||
end | ||
|
||
def make_reservation(check_in,check_out,room_id, guest_id=nil) | ||
|
||
reservation_id = (@all_reservations.count + 1) | ||
room= find_room_by_id(room_id) | ||
check_in_date = Date.parse(check_in) | ||
check_out_date = Date.parse(check_out) | ||
|
||
check_valid_dates(check_in_date,check_out_date) | ||
|
||
if available_rooms(check_in_date,check_out_date).include?(room) | ||
|
||
reservation = HotelBooking::Reservation.new(check_in_date,check_out_date,room_id, reservation_id) | ||
|
||
room.reserve_room(check_in_date,check_out_date,reservation_id, guest_id) | ||
|
||
@all_reservations << reservation | ||
else | ||
raise ArgumentError.new("This room is already reserved for these dates") | ||
end | ||
|
||
end | ||
|
||
def make_block_reservation(block_id,room_id,guest_id = nil) | ||
reservation_id = (@all_reservations.count + 1) | ||
room= find_room_by_id(room_id) | ||
block= find_block_by_id(block_id) | ||
|
||
raise ArgumentError.new("This block does not exist") if !(@all_blocks.include?(find_block_by_id(block_id))) | ||
raise ArgumentError.new("This room is not in the block") if !(block.room_ids.include?(room_id)) | ||
|
||
reservation = HotelBooking::BlockReservation.new(block.check_in,block.check_out,room_id, reservation_id, block.discounted_rate) | ||
reservation.block_id = block_id | ||
|
||
room.reserve_block_room(block_id,reservation.id, guest_id=nil) | ||
|
||
@all_reservations << reservation | ||
|
||
end | ||
|
||
def find_room_by_id(room_id) | ||
@all_rooms.each {|room| return room if room.id == room_id} | ||
|
||
raise ArgumentError.new "Sorry, we don't have a room matching that ID number." | ||
end | ||
|
||
def find_res_by_date(date_str) | ||
date_object= Date.parse(date_str) | ||
@all_reservations.select {|reservation| ((reservation.check_in)..(reservation.check_out)).include?(date_object)} | ||
end | ||
|
||
def find_block_by_id(block_id) | ||
|
||
@all_blocks.each {|block| return block if block.id == block_id} | ||
raise ArgumentError.new "Sorry, we don't have a block matching that ID number." | ||
end | ||
|
||
def find_available_rooms_by_block(block_id) | ||
block= find_block_by_id(block_id) | ||
|
||
block_rooms = block.room_ids.map {|id| find_room_by_id(id)} | ||
|
||
block_rooms.select {|room| room.blocks_available.include?(block_id)} | ||
end | ||
|
||
def check_valid_block(check_in,check_out,room_ids) | ||
raise ArgumentError.new("Number of rooms in a block must be 5 or under") if room_ids.count > 5 | ||
|
||
available_rooms_ids = available_rooms(check_in,check_out).map {|room| room.id} | ||
|
||
room_ids.each do |room_id| | ||
raise ArgumentError.new("This room is already reserved for the dates provided") if !(available_rooms_ids.include?(room_id)) | ||
end | ||
|
||
return true | ||
|
||
end | ||
|
||
def check_valid_dates(check_in, check_out) | ||
if check_in < Date.today || check_out < Date.today | ||
raise ArgumentError.new("Can't make reservations for days earlier than today") | ||
end | ||
|
||
if check_in.class != Date ||check_out.class != Date | ||
raise ArgumentError.new("Please provide a valid date") | ||
end | ||
|
||
if check_out < check_in | ||
raise ArgumentError.new("Invalid Date Range: Check out date is earlier than check-in date.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might want to pick a different Error besides |
||
end | ||
|
||
end | ||
|
||
def self.setup_rooms | ||
i = 1 | ||
standard_rooms = [] | ||
|
||
until standard_rooms.count == NUM_STANDARD_ROOMS | ||
room = HotelBooking::Room.new(i) | ||
standard_rooms << room | ||
i += 1 | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can probably do this same thing with NUM_STANDARD_ROOMS.times do |index|
room = HotelBooking::Room.new(index + 1)
standard_rooms << room
end or
|
||
|
||
return standard_rooms | ||
end | ||
|
||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
### OPTIONAL CLASS | ||
|
||
module Hotel | ||
class Guest | ||
|
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'date' | ||
module HotelBooking | ||
|
||
class Reservation | ||
attr_accessor :id, :guest, :check_in, :check_out, :room_id | ||
attr_reader :all_reservations, :type, :rate | ||
|
||
def initialize(check_in,check_out,room_id, res_id, rate = 200, guest = nil) | ||
@id = res_id | ||
@check_in = check_in #ruby Date object | ||
@check_out = check_out #ruby Date object | ||
@room_id= room_id | ||
@guest = guest | ||
@rate = rate | ||
@type= :standard | ||
end #end initialize | ||
|
||
def cost | ||
num_nights_charged * @rate | ||
end | ||
|
||
def num_nights_charged | ||
(check_out.mjd - check_in.mjd) | ||
end | ||
|
||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'date' | ||
|
||
module HotelBooking | ||
|
||
class Room | ||
attr_reader :id, :nightly_rate, :type, :reserv_ids, :all_dates, :block_ids, :blocks_available | ||
|
||
def initialize(id_number, nightly_rate = 200) | ||
@id = id_number | ||
@nightly_rate = nightly_rate | ||
@type = :standard | ||
@reserv_ids = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are |
||
@block_ids = [] | ||
@all_dates = [] | ||
@blocks_available = [] | ||
end | ||
|
||
def reserve_room(check_in,check_out,reservation_id, guest_id=nil) | ||
|
||
(check_in...check_out).each do |date| | ||
@all_dates << date | ||
end | ||
|
||
@reserv_ids << reservation_id | ||
end | ||
|
||
def reserve_block_room(block_id, reservation_id, guest_id=nil) | ||
raise ArgumentError.new("This Block room is not available for this block reservation") if !(@blocks_available.include?(block_id)) | ||
|
||
@blocks_available.delete(block_id) | ||
end | ||
|
||
|
||
def block_room(check_in,check_out,block_id) | ||
(check_in...check_out).each do |date| | ||
return false if @all_dates.include?(date) | ||
end | ||
|
||
@blocks_available << block_id | ||
|
||
(check_in...check_out).each do |date| | ||
@all_dates << date | ||
end | ||
end | ||
|
||
def available_all_days?(check_in, check_out) | ||
(check_in..check_out).each do |date| | ||
return false if @all_dates.include?(date) | ||
end | ||
|
||
return true | ||
end | ||
|
||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require 'date' | ||
|
||
require_relative 'spec_helper' | ||
|
||
describe "HotelBooking::BlockReservation class" do | ||
describe "initialize" do | ||
it "initalizes with the appropriate reservation type" do | ||
check_in = Date.parse("2018-10-03") | ||
check_out = Date.parse("2018-10-06") | ||
room_id = 1 | ||
b_res_id = 14 | ||
discounted_rate = 5 | ||
block_id = 42 | ||
|
||
new_block_res = HotelBooking::BlockReservation.new(check_in, check_out,room_id,b_res_id,discounted_rate, block_id) | ||
|
||
new_block_res.must_be_instance_of HotelBooking::BlockReservation | ||
new_block_res.type.must_equal :block | ||
|
||
end | ||
end | ||
|
||
describe "num_nights_charged" do | ||
|
||
it "correctly inherits the num_nights_charged method from the HotelBooking::Reservation class" do | ||
blockres1 = HotelBooking::BlockReservation.new(Date.parse("2018-02-14"), Date.parse("2018-02-16"),3,14,5) | ||
|
||
blockres1.num_nights_charged.must_equal 2 | ||
end | ||
end | ||
|
||
describe "cost" do | ||
it "calculates cost with a discounted rate" do | ||
discounted_rate = 5 | ||
blockres1 = HotelBooking::BlockReservation.new(Date.parse("2018-02-14"), Date.parse("2018-02-16"),14,42,discounted_rate) | ||
blockres1.cost.must_equal 10 | ||
|
||
blockres2 = HotelBooking::BlockReservation.new(Date.parse("2018-12-01"), Date.parse("2018-12-02"),1,5,discounted_rate) | ||
|
||
blockres2.cost.must_equal 5 | ||
end | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require_relative 'spec_helper' | ||
|
||
describe "HotelBooking::Block class " do | ||
describe "initialize" do | ||
before do | ||
@check_in_str = "2018-10-03" | ||
@check_out_str = "2018-10-06" | ||
@new_hotel = HotelBooking::Hotel.new | ||
@room_ids= [1,2,3] | ||
@block_id = "Amy's Party" | ||
@discounted_rate = 5 | ||
@new_block = HotelBooking::Block.new(Date.parse(@check_in_str), Date.parse(@check_out_str),@room_ids,@discounted_rate,@block_id) | ||
end | ||
|
||
it "initalizes with attributes that we can access in our booking system" do | ||
@new_block.must_be_instance_of HotelBooking::Block | ||
|
||
@new_block.id.must_equal @block_id | ||
@new_block.check_in.to_s.must_equal @check_in_str | ||
@new_block.check_out.to_s.must_equal @check_out_str | ||
|
||
end | ||
|
||
it "stores an array of room ids " do | ||
@new_block.room_ids.must_be_instance_of Array | ||
@new_block.room_ids.must_equal @room_ids | ||
@new_block.room_ids.each do |id| | ||
id.must_be_instance_of Integer | ||
end | ||
end | ||
|
||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love all the small helper methods you made :D I wish that there were a better place to put this specific helper method about checking if it's a valid date that wasn't in
Hotel
, but I can't think of a better place at the moment.