-
Notifications
You must be signed in to change notification settings - Fork 46
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
Karis - Edges - Hotel #27
base: master
Are you sure you want to change the base?
Changes from 58 commits
9764369
f84bf41
511ead2
bb9a903
8609b2a
05a329a
7cfd993
0a433dc
7dbba01
2b292b8
b15f566
00ef5ed
87edfda
a52808e
aab529c
95de6be
a032ab7
9632394
e8c00f0
ee5555d
9e47d43
4fa4d3b
6afd0c1
89ff764
42bbd41
1b1212c
4bd629b
c8d4d2d
1e04809
d721fa5
5091434
adc40e1
2417864
677185b
c0c9721
f1b9bf8
53b73d6
6a77f5b
929977f
e51b6f8
f47355e
47864f1
6a4136b
d1ea68c
ebafef3
1fb7714
9fb37dd
cef78da
7ce9572
42d4c53
6d99938
de76799
6f851e3
14c15b1
273eddc
a79583b
c2f08f7
bb156ac
af79d2a
f748e4e
fc4e065
ae0e4ae
9bfcbcb
6aeea07
53d07af
e8f1196
660979a
59bf096
1f4a43f
a1a99e0
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
guard :minitest, bundler: false, rubygems: false do | ||
guard :minitest, bundler: false, autorun: false, rubygems: false do | ||
# with Minitest::Spec | ||
watch(%r{^spec/(.*)_spec\.rb$}) | ||
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } | ||
watch(%r{^lib/(.+)\.rb$}) { |m| "speguc/#{m[1]}_spec.rb" } | ||
watch(%r{^spec/spec_helper\.rb$}) { 'spec' } | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
require_relative 'reservation_creator' | ||
require 'pry' | ||
|
||
module Hotel | ||
class BookingSystem | ||
attr_reader :rooms, :reservations, :dates | ||
|
||
def initialize | ||
@reservations = [] | ||
@rooms = [*1..20] | ||
@dates = [] | ||
end | ||
|
||
def make_reservation(check_in_date:, check_out_date:) | ||
# TODO find a room that's available | ||
|
||
room_number = get_available_room(check_in_date: check_in_date, check_out_date: check_out_date) | ||
|
||
reservation = ReservationCreator.new(check_in_date: check_in_date, check_out_date: check_out_date, room_number: room_number) | ||
|
||
|
||
|
||
# @dates.each do |date_with_room| | ||
# date | ||
# if reservation.date_range.include?(date) && reservation.room_number == room | ||
# | ||
# reservation.room_number += 1 | ||
# end | ||
# binding.pry | ||
# end | ||
# end | ||
|
||
|
||
@reservations << reservation | ||
|
||
return reservation | ||
end | ||
|
||
def get_available_room(check_in_date:, check_out_date:) | ||
return @rooms.first | ||
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'd love to get more insight into your thoughts here of how you wanted to continue and push this code -- feel free to add comments that include your pseudocode next time :) |
||
end | ||
|
||
def list_all_rooms | ||
return @rooms | ||
end | ||
|
||
# def add_dates_with_rooms | ||
# | ||
# @reservations.each do |booking| | ||
# | ||
# booking.date_range.each do |date| | ||
# date_with_room = {} | ||
# # binding.pry | ||
# | ||
# date_with_room[date] = booking.room_number | ||
# @dates << date_with_room | ||
# end | ||
# end | ||
# | ||
# return @dates | ||
# end | ||
|
||
def list_reservations_by_date(date) | ||
specific_date = Date.parse("#{date}") | ||
|
||
bookings_by_date = [] | ||
@reservations.each do |booking| | ||
dates = booking.date_range | ||
if dates.include?(specific_date) | ||
bookings_by_date << booking | ||
end | ||
end | ||
|
||
return bookings_by_date | ||
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. This method looks pretty good to me. I see the following logic: We start with figuring out the Looking through the entire collection of reservations in Not bad -- can't wait to see more! |
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'date' | ||
|
||
module Hotel | ||
class ReservationCreator | ||
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. When I look at this class, it really feels like the attributes, state, behaviors that this class has resemble more of representing a Reservation. If this object were a "ReservationCreator," I would imagine that its behaviors would be more about making Reservation instances, and wouldn't need a check in or check out date. |
||
attr_reader :check_in_date, :check_out_date | ||
attr_accessor :room_number | ||
|
||
def initialize(input) | ||
@check_in_date = Date.parse("#{input[:check_in_date]}") | ||
|
||
@check_out_date = Date.parse("#{input[:check_out_date]}") | ||
raise StandardError, "Checkout date cannot be before checkin date" unless input[:check_in_date] < input[:check_out_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. I like this post-fix conditional! But watch your indentation ;) |
||
@room_number = input[:room_number].nil? ? [] : input[:room_number] | ||
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. This code says: if in the passed-in I think it makes sense that |
||
end | ||
|
||
def date_range | ||
date_range = [*check_in_date...check_out_date] | ||
return date_range | ||
end | ||
|
||
def calculate_booking_cost | ||
cost = date_range.length * 200 | ||
return cost | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require_relative 'spec_helper' | ||
|
||
describe "BookingSystem class" do | ||
before do | ||
@booking = Hotel::BookingSystem.new | ||
@reservation = @booking.make_reservation(check_in_date: 180904, check_out_date: 180907) | ||
end | ||
|
||
it "create BookingSystem class" do | ||
expect(@booking).must_be_kind_of Hotel::BookingSystem | ||
end | ||
|
||
it "initialize method" do | ||
expect(@booking.reservations).must_be_kind_of Array | ||
end | ||
|
||
it "returns array of all room numbers in hotel" do | ||
expect(@booking.list_all_rooms).must_be_kind_of Array | ||
expect(@booking.list_all_rooms).must_equal [*1..20] | ||
end | ||
|
||
it "returns array of dates" do | ||
expect(@reservation).must_be_kind_of Hotel::ReservationCreator | ||
expect(@reservation.date_range).must_equal [Date.parse("180904"), Date.parse("180905"), Date.parse("180906")] | ||
end | ||
|
||
it "returns the total cost of the booking" do | ||
expect(@reservation.calculate_booking_cost).must_equal 600 | ||
end | ||
|
||
it "list all bookings of that date" do | ||
bad_reservation = @booking.make_reservation(check_in_date: 180909, check_out_date: 1809010) | ||
|
||
expect(@booking.list_reservations_by_date(180904)).must_include @reservation | ||
expect(@booking.list_reservations_by_date(180904)).wont_include bad_reservation | ||
end | ||
|
||
# it "does not assign room when room is booked for that date" do | ||
# bad_reservation = @booking.make_reservation(check_in_date: 180904, check_out_date: 180905) | ||
# | ||
# expect() | ||
# | ||
# end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require_relative 'spec_helper' | ||
|
||
describe "ReservationCreator class" do | ||
before do | ||
@reservation = Hotel::ReservationCreator.new({check_in_date: 180904, check_out_date: 180905}) | ||
end | ||
|
||
it "initialize method" do | ||
expect(@reservation).must_be_kind_of Hotel::ReservationCreator | ||
expect(@reservation.check_in_date).must_be_kind_of Date | ||
expect(@reservation.check_out_date).must_be_kind_of Date | ||
end | ||
|
||
it "raises ArgumentError if check out date is before check in date" do | ||
expect{(list = Hotel::ReservationCreator.new(180904, 180903))}.must_raise StandardError | ||
end | ||
|
||
it "returns all dates in date range" do | ||
expect(@reservation.date_range).must_be_kind_of Array | ||
expect(@reservation.date_range.length).must_equal 1 | ||
expect(@reservation.date_range).must_equal [Date.parse("180904")] | ||
end | ||
|
||
it "returns cost of that date range" do | ||
expect(@reservation.calculate_booking_cost).must_be_kind_of Integer | ||
expect(@reservation.calculate_booking_cost).must_equal 200 | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
require 'simplecov' | ||
SimpleCov.start | ||
|
||
require 'minitest' | ||
require 'minitest/autorun' | ||
require 'minitest/reporters' | ||
# Add simplecov | ||
require 'minitest/skip_dsl' | ||
require 'awesome_print' | ||
|
||
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new | ||
|
||
# Require_relative your lib files here! | ||
require_relative '../lib/reservation_creator' | ||
require_relative '../lib/booking_system' |
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 think from a birds-eye view, this method
make_reservation
is set up for success. It's outline is the following:@reservations
I think that the rest of the work for wave 2 is just filling in the detail for those steps, and those details will be filled in with the helper methods. I think that this method looks really good as is though.