forked from AdaGold/hotel
-
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
Ampers - Sara S - Hotel #32
Open
CheerOnMars
wants to merge
43
commits into
Ada-C9:master
Choose a base branch
from
CheerOnMars:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 42 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
cdcf55f
add reservation class and test methods
CheerOnMars 8587c1f
updated length method to ensure output is an integer
CheerOnMars f5f634c
created room class, method, and test file
CheerOnMars c547e7b
create spec helper
CheerOnMars a3fdcdd
created hotel_admin method and tests to return array of reservations …
CheerOnMars 45907e8
updated filed names so they could be read by rake
CheerOnMars f1e264e
created Rakefile
CheerOnMars a7db229
changed name of local variage in initialize method in Room class
CheerOnMars 4dd8d16
deleted room_specs.rb and replaced it with room_spec.rb
CheerOnMars f99f765
deleted reservation_specs.rb and replaced it with reservation_spec.rb…
CheerOnMars 509fef8
add room to initialize method in reservation class, add self method f…
CheerOnMars 3821f9e
corrected method to access reservations for a certain day
CheerOnMars 66170d4
changed start_date and end_date to checkin_date and checkout_date
CheerOnMars de77f64
adjusted variable names in lib/hotel_admin.rb for added clarity
CheerOnMars daddef4
updated tests for HotelAdmin's method of returning rooms
CheerOnMars 3680efe
adjusted variable names in lib/room.rb for added clarity
CheerOnMars 883b1a1
adjusted method names in lib/reservation.rb for added clarity
CheerOnMars ca4ff0d
updated tests to account for adjusted method names in lib/reservation…
CheerOnMars 44b474c
rearranged order of hotel_admin tests
CheerOnMars ee581ee
rearrange order of methods
CheerOnMars 3aee111
removed room class and specs, added room to HotelAdmin class. updated…
CheerOnMars 32815d1
updated reservation class to grey out lines that parsed the date into…
CheerOnMars c633a11
add test to HotelAdmin class to check that returns a list of all the …
CheerOnMars de23dda
In HotelAdmin class, added method to view available rooms, and change…
CheerOnMars 9fef03e
removed unnecessary comments
CheerOnMars 779da5c
removed unnecessary comments and added reserve_available_room method …
CheerOnMars a217f7e
removed unnecessary comments and added tests for reserve_available_ro…
CheerOnMars 21fbb57
trimmed down the tests for the HotelAdmin class's methods
CheerOnMars 5982f91
add block class lib and spec files
CheerOnMars 474e97d
added lib/block and removed lib/room as required relatives
CheerOnMars 428a5a9
removed lib/room as required relative
CheerOnMars edb3810
holding off on making block its own class for now
CheerOnMars a0042c2
holding off on making block its own class for now
CheerOnMars ba3c378
small format change
CheerOnMars 9c6e3e4
updated HotelAdmin class and its tests to include block functionality
CheerOnMars 60231d0
add status to reservation class
CheerOnMars 74b830f
update method for room holds, add appropriate tests
CheerOnMars d217828
removed unncessary status and price_night methods
CheerOnMars d2e68c9
added missing comma
CheerOnMars f728d7d
added party_name to reservations class
CheerOnMars f8ac9ef
tried to update status
CheerOnMars 6c512e0
tried to update method and tests to reserve a room in a block
CheerOnMars 256953b
corrected design-activity
CheerOnMars File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = true | ||
t.test_files = FileList['specs/*_spec.rb'] | ||
end | ||
|
||
task default: :test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# require 'time' | ||
# require_relative 'reservation' | ||
# require_relative 'hotel_admin' | ||
# | ||
# module Hotel | ||
# class Block | ||
# attr_reader :block_start_date, :block_end_date, :room_amt | ||
# | ||
# def initialize(input) | ||
# | ||
# if input[:block_start_date] == nil || input[:block_end_date] == nil | ||
# raise ArgumentError.new("Date must be a date.") | ||
# end | ||
# | ||
# if input[:block_start_date] >= input[:block_end_date] | ||
# raise ArgumentError.new("End date must be after start date.") | ||
# end | ||
# | ||
# if input[:room_amt] > 5 || input[:room_amt] < 1 | ||
# raise ArgumentError.new("Rooms must be between 1 and 5.") | ||
# end | ||
# | ||
# # if input[:room_num] > Hotel::HotelAdmin.view_available_rooms(input[:block_start_date], input[:block_end_date]) | ||
# # raise ArgumentError.new("There are not enough rooms available during that time.") | ||
# # end | ||
# | ||
# if input[:room_amt] > 5 || input[:room_amt] < 1 | ||
# raise ArgumentError.new("Rooms must be between 1 and 5.") | ||
# end | ||
# | ||
# @block_start_date = input[:block_start_date] | ||
# @block_end_date = input[:block_end_date] | ||
# @room_num = input[:room_amt] | ||
# end | ||
# | ||
# | ||
# end | ||
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
require 'time' | ||
require_relative 'reservation' | ||
|
||
module Hotel | ||
class HotelAdmin | ||
attr_reader :rooms, :reservations, :reservation, :block_start_date, :block_end_date, :room_amt, :blocks, :block, :rooms_held, :block_name | ||
attr_accessor :status | ||
|
||
def initialize | ||
@rooms = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] | ||
@reservations = [] | ||
@blocks = [] | ||
@holds_reservations = [] | ||
@rooms_held = [] | ||
end | ||
|
||
def add_reservation(reservation) | ||
#note: this is tightly coupled, I think. | ||
@reservations << reservation | ||
@reservation = reservation | ||
return @reservation | ||
end | ||
|
||
def calc_reservations(reservation) | ||
reservation.price_night * reservation.calc_duration | ||
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. I think this logic would be better inside the reservation object |
||
end | ||
|
||
def access_reservations(day) | ||
days_reservations = [] | ||
@reservations.each do |reservation| | ||
if (reservation.checkin_date...reservation.checkout_date).include?(day) | ||
days_reservations << reservation | ||
end | ||
end | ||
return days_reservations | ||
end | ||
|
||
def view_available_rooms(checkin_request, checkout_request) | ||
arr_available_rooms = @rooms.map{ |room| room } | ||
date_range_requested = (checkin_request...checkout_request).map{ |date| date} | ||
@reservations.each do |res| | ||
date_range_requested.each do |day_requested| | ||
if (res.checkin_date...res.checkout_date).include?(day_requested) | ||
arr_available_rooms.delete(res.room_id) | ||
end | ||
end | ||
end | ||
return arr_available_rooms | ||
end | ||
|
||
def reserve_available_room(checkin_request, checkout_request) | ||
avail_room = view_available_rooms(checkin_request, checkout_request)[0] | ||
add_reservation(Hotel::Reservation.new({checkin_date: checkin_request, checkout_date: checkout_request, room_id: avail_room})) | ||
end | ||
|
||
def create_block(input) | ||
|
||
if input[:block_start_date] == nil || input[:block_end_date] == nil | ||
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. All of this data validation should be in an |
||
raise ArgumentError.new("Date must be a date.") | ||
end | ||
|
||
if input[:block_start_date] >= input[:block_end_date] | ||
raise ArgumentError.new("End date must be after start date.") | ||
end | ||
|
||
if input[:room_amt] > 5 || input[:room_amt] < 1 | ||
raise ArgumentError.new("Rooms must be between 1 and 5.") | ||
end | ||
|
||
if input[:room_amt] > 5 || input[:room_amt] < 1 | ||
raise ArgumentError.new("Rooms must be between 1 and 5.") | ||
end | ||
|
||
if input[:room_amt] > view_available_rooms(input[:block_start_date], input[:block_end_date]).count | ||
raise ArgumentError.new("There are not enough rooms available during that time.") | ||
end | ||
@block_start_date = input[:block_start_date] | ||
@block_end_date = input[:block_end_date] | ||
@room_amt = input[:room_amt] | ||
@block_name = input[:group_name] | ||
@blocks << input | ||
@block = input | ||
input[:room_amt].times do |i| | ||
avail_room = view_available_rooms(input[:block_start_date], input[:block_end_date])[0] | ||
new_res = add_reservation(Hotel::Reservation.new({checkin_date: input[:block_start_date], checkout_date: input[:block_end_date], room_id: avail_room, status: "held", group_name: input[:group_name]})) | ||
@rooms_held << avail_room | ||
@holds_reservations << new_res | ||
end | ||
return @block | ||
end | ||
|
||
def return_blocks_rooms(input) | ||
@rooms_held | ||
end | ||
|
||
def return_held_reservations | ||
@holds_reservations | ||
end | ||
|
||
def check_block_availability(group_name) | ||
arr_available_held_rooms = [] | ||
@holds_reservations | ||
@holds_reservations.each do |res| | ||
if res.status == "held" && res.party_name == group_name | ||
arr_available_held_rooms << res | ||
end | ||
end | ||
return arr_available_held_rooms | ||
end | ||
|
||
def reserve_room_in_block(group_name) | ||
block_res = check_block_availability(group_name)[0] | ||
block_res.status = "booked" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require 'time' | ||
|
||
module Hotel | ||
class Reservation | ||
attr_reader :checkin_date, :checkout_date, :room_id, :price_night, :party_name | ||
attr_accessor :status | ||
|
||
def initialize(input) | ||
|
||
if input[:checkin_date] == nil || input[:checkout_date] == nil | ||
raise ArgumentError.new("Date must be a date.") | ||
end | ||
|
||
if input[:checkin_date] >= input[:checkout_date] | ||
raise ArgumentError.new("End date must be after start date.") | ||
end | ||
|
||
@checkin_date = input[:checkin_date] | ||
@checkout_date = input[:checkout_date] | ||
@room_id = input[:room_id] | ||
@price_night = 200 | ||
@status = input[:status] | ||
@party_name = input[:group_name] | ||
end | ||
|
||
def status | ||
return @status | ||
end | ||
|
||
def calc_duration | ||
((checkin_date...checkout_date).map{ |date| date}).count | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# | ||
# module Hotel | ||
# class Room | ||
# attr_reader :room_num, :cost | ||
# COST = 200 | ||
# | ||
# def initialize(room_num) | ||
# @room_num = room_num | ||
# end | ||
# | ||
# # def price | ||
# # @cost = COST | ||
# # end | ||
# | ||
# end | ||
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# require_relative 'spec_helper' | ||
# | ||
# | ||
# describe "Block class" do | ||
# | ||
# describe "Initializer" do | ||
# before do | ||
# @block = Hotel::Block.new({block_start_date: "2015-07-20", block_end_date: "2015-07-25", room_num: 5}) | ||
# end | ||
# | ||
# it "is an instance of Hotel::Block" do | ||
# @block.must_be_kind_of Hotel::Block | ||
# end | ||
# | ||
# it "returns an error if block attempt has more than 5 rooms" do | ||
# proc{ Hotel::Block.new({block_start_date: "2015-07-20", block_end_date: "2015-07-25", room_num: 6})}.must_raise ArgumentError | ||
# end | ||
# | ||
# it "returns an error if block attempt has less than 1 room" do | ||
# proc{ Hotel::Block.new({block_start_date: "2015-07-20", block_end_date: "2015-07-25", room_num: 0})}.must_raise ArgumentError | ||
# end | ||
# | ||
# it "throws an argument error for a bad end date" do | ||
# proc{ Hotel::Block.new({block_start_date: "2015-07-20", block_end_date: nil }) }.must_raise ArgumentError | ||
# end | ||
# | ||
# it "throws an argument error for a bad start date" do | ||
# proc{ Hotel::Block.new({block_start_date: nil, block_end_date: "2015-07-20", room_num: 3 }) }.must_raise ArgumentError | ||
# end | ||
# | ||
# | ||
# it "throws an argument error when end date isn't after start date" do | ||
# proc{ Hotel::Block.new({block_start_date: "2015-07-20", block_end_date: "2015-07-20", room_num: 3 }) }.must_raise ArgumentError | ||
# proc{ Hotel::Block.new({block_start_date: "2015-07-21", block_end_date: "2015-07-20", room_num: 3 }) }.must_raise ArgumentError | ||
# end | ||
# | ||
# it "can create a block of rooms" do | ||
# | ||
# end | ||
# | ||
# it "only includes rooms that are available for the given date range" do | ||
# | ||
# end | ||
# | ||
# it "excludes rooms in the block for reservations by general public" do | ||
# end | ||
# | ||
# end | ||
# | ||
# # describe "create_block method" do | ||
# # | ||
# # it "" do | ||
# # end | ||
# # | ||
# # end | ||
# | ||
# describe "check_block_availability method" do | ||
# | ||
# it "can check whether a given block has any rooms available" do | ||
# end | ||
# | ||
# end | ||
# | ||
# describe "reserve_room_in_block" do | ||
# | ||
# it "can reserve a room from within a block of rooms" do | ||
# end | ||
# | ||
# end | ||
# | ||
# end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why set this as an instance variable here?