-
Notifications
You must be signed in to change notification settings - Fork 49
Leaves - Elizabeth #43
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
base: master
Are you sure you want to change the base?
Changes from 14 commits
fa4e0c3
442414c
f611cfa
1b14ccb
5b88279
8ac1ac4
e4c0e68
543d0a1
ca47db4
4bfa105
7eeba2a
7a05901
186cfbb
6cd210e
67ec429
9610cb2
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,22 @@ | ||
| module Booking | ||
| class DateRange | ||
|
|
||
| attr_reader :start_date, :end_date | ||
|
|
||
| def initialize(start_date, end_date) | ||
| @start_date = start_date | ||
| @end_date = end_date | ||
| end | ||
|
|
||
| def total_nights | ||
| nights = end_date - start_date | ||
|
|
||
| if nights == 0 | ||
| return raise ArgumentError, "Must book the room for at least one night." | ||
| else | ||
| return nights | ||
| end | ||
| end | ||
|
|
||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| require_relative 'date_range' | ||
| require_relative 'reservation' | ||
| require_relative 'room' | ||
|
|
||
| require 'pry' | ||
|
|
||
| module Booking | ||
| class Hotel | ||
|
|
||
| attr_reader :reservations, :unavailable_rooms | ||
| attr_accessor :rooms | ||
|
|
||
| def initialize(num_of_rooms) | ||
| if num_of_rooms == nil || num_of_rooms <= 0 | ||
| raise ArgumentError, "Hotel must have a postive number of rooms greater than 0." | ||
| end | ||
|
|
||
| @rooms = make_rooms(num_of_rooms) | ||
| @reservations = [] | ||
| @unavailable_rooms = [] | ||
| end | ||
|
|
||
| def make_rooms(num) | ||
| room_array = [] | ||
| i = 1 | ||
| while i < num + 1 | ||
| room = Booking::Room.new(i) | ||
| room_array << room | ||
| i += 1 | ||
| end | ||
| return room_array | ||
| end | ||
|
|
||
| def make_reservation(start_date, end_date) | ||
| available_rooms_list = available_rooms(start_date,end_date) | ||
| new_date_range = Booking::DateRange.new(start_date, end_date) | ||
| new_total_nights = new_date_range.total_nights | ||
| new_cost = new_total_nights * 200 | ||
| room = available_rooms_list.sample | ||
| new_reservation = Booking::Reservation.new(new_date_range, new_total_nights, new_cost, room) | ||
|
|
||
| reservations.push(new_reservation) | ||
| end | ||
|
|
||
| def find_reservation(start_date, end_date) | ||
| reservation_array = [] | ||
| reservations.each do |reservation| | ||
| if reservation.date_range.start_date == start_date && reservation.date_range.end_date == end_date | ||
| reservation_array << reservation | ||
| end | ||
| end | ||
| return reservation_array | ||
| end | ||
|
|
||
| def available_rooms(start_date, end_date) | ||
| if start_date > end_date | ||
| raise ArgumentError, "End date of reservation must be after start date." | ||
| else | ||
| reservations.each do |reservation| | ||
| if reservation.date_range.end_date > start_date || reservation.date_range.start_date < end_date | ||
| if !unavailable_rooms.include?(reservation.room.number) | ||
| unavailable_rooms << reservation.room.number | ||
| end | ||
| end | ||
| end | ||
|
|
||
| a_rooms = rooms | ||
| i = 0 | ||
| a_rooms.each do |room| | ||
| if unavailable_rooms.include?(room.number) | ||
| a_rooms.delete(room) | ||
| else | ||
| i += 1 | ||
| end | ||
| end | ||
|
|
||
| if a_rooms == [] | ||
| raise StandardError, "There are no rooms available for that date range." | ||
| else | ||
| return a_rooms | ||
| end | ||
| end | ||
| end | ||
|
|
||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| module Booking | ||
| class Hotel_Block < Reservation | ||
| # def initialize | ||
| # end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| require_relative 'hotel' | ||
|
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. /Users/devin/Documents/Ada/c12/hotel/lib/reservation.rb:1: warning: loading in progress, circular require considered harmful - /Users/devin/Documents/Ada/c12/hotel/lib/hotel.rb |
||
| require 'pry' | ||
|
|
||
|
|
||
|
|
||
| module Booking | ||
| class Reservation | ||
| attr_reader :date_range, :total_cost, :total_nights, :room | ||
|
|
||
| def initialize(date_range, total_nights, total_cost, room) | ||
| @date_range = date_range | ||
| @room = room | ||
| @total_nights = total_nights | ||
| @total_cost = total_cost | ||
| 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. If you have a class that has no methods besides |
||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| module Booking | ||
| class Room | ||
|
|
||
| attr_reader :number, :cost | ||
|
|
||
| def initialize (number, cost: 200) | ||
|
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 space causes this warning: /Users/devin/Documents/Ada/c12/hotel/lib/room.rb:6: warning: parentheses after method name is interpreted as an argument list, not a decomposed argument |
||
| @number = number | ||
| @cost = cost | ||
|
|
||
| end | ||
|
|
||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| 1. I wanted to have hotel_block be a child of reservation but I am not sure if it would work with the room instace variable that was | ||
| written into reservation. | ||
|
|
||
| 2. The naming could definitely be clearer throughout the whole project. | ||
| 3. There are a few methods inside of hotel that have quite a few nested if statements and I would clean those up to be clearer. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| require_relative 'test_helper' | ||
| require 'pry' | ||
|
|
||
| describe "DateRange" do | ||
| describe "Initializer" do | ||
|
|
||
| before do | ||
| start_date = Date.new(2016, 10, 21) | ||
| end_date = Date.new(2016, 10, 30) | ||
| @test_date_range = Booking::DateRange.new(start_date, end_date) | ||
| end | ||
|
|
||
| it "creates and instance of DateRange" do | ||
| expect(@test_date_range).must_be_kind_of Booking::DateRange | ||
| end | ||
|
|
||
| it "is set up for specific attributes and data types" do | ||
| [:start_date, :end_date].each do |attribute| | ||
| expect(@test_date_range).must_respond_to attribute | ||
| end | ||
|
|
||
| expect(@test_date_range.start_date).must_be_kind_of Date | ||
| expect(@test_date_range.end_date).must_be_kind_of Date | ||
|
|
||
| end | ||
|
|
||
| end | ||
|
|
||
| describe "Total_Nights" do | ||
|
|
||
| it "calculates the total amount of nights for a reservation" do | ||
| start_date = Date.new(2016, 10, 21) | ||
| end_date = Date.new(2016, 10, 30) | ||
| @test_date_range = Booking::DateRange.new(start_date, end_date) | ||
| expect(@test_date_range.total_nights).must_equal 9 | ||
| end | ||
|
|
||
| it "raises an ArgumentError if end and start date are the same" do | ||
| start_date = Date.new(2016, 10, 21) | ||
| end_date = Date.new(2016, 10, 21) | ||
| @test_date_range = Booking::DateRange.new(start_date, end_date) | ||
|
|
||
| expect{@test_date_range.total_nights}.must_raise ArgumentError | ||
|
|
||
| end | ||
|
|
||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| require_relative 'test_helper' | ||
|
|
||
| describe 'Hotel_Block' do | ||
| describe 'Initialize' do | ||
|
|
||
| it "creates an instance of Hotel_Block" do | ||
| start_date = Date.new(2019, 10, 10) | ||
| end_date = Date.new(2019 10, 15) | ||
|
||
| date_range = Booking::DateRange.new(start_date, end_date) | ||
| total_nights = 5 | ||
| total_cost = 1000 | ||
| wedding_block = Booking::Hotel_Block.new(date_range, total_nights, total_cost, room) | ||
|
||
| expect(wedding_block).must_be_kind_of Booking::Hotel_Block | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| require_relative 'test_helper' | ||
|
|
||
| def build_test_hotel | ||
| return Booking::Hotel.new( | ||
| 20 | ||
| ) | ||
| end | ||
|
|
||
| describe "Hotel Class" do | ||
|
|
||
| describe "Initializer" do | ||
|
|
||
| it "is set up for specific attributes and data types" do | ||
| the_grand_budapest_hotel = build_test_hotel | ||
| [:rooms, :reservations].each do |attribute| | ||
| expect(the_grand_budapest_hotel).must_respond_to attribute | ||
| end | ||
|
|
||
| expect(the_grand_budapest_hotel.rooms).must_be_kind_of Array | ||
| expect(the_grand_budapest_hotel.reservations).must_be_kind_of Array | ||
| end | ||
|
|
||
| it "is an instance of Hotel Class" do | ||
| the_grand_budapest_hotel = build_test_hotel | ||
| expect(the_grand_budapest_hotel).must_be_kind_of Booking::Hotel | ||
| end | ||
|
|
||
| it "@rooms is the correct length" do | ||
| the_grand_budapest_hotel = build_test_hotel | ||
| expect(the_grand_budapest_hotel.rooms.length).must_equal 20 | ||
| end | ||
|
|
||
| it "must be initiated with a a postive amount of rooms greater than 0" do | ||
| expect{Booking::Hotel.new(0)}.must_raise ArgumentError | ||
| expect{Booking::Hotel.new(nil)}.must_raise ArgumentError | ||
| end | ||
| end | ||
|
|
||
| describe "Make_Rooms" do | ||
| it "creates an instance of room" do | ||
| the_grand_budapest_hotel = build_test_hotel | ||
| array = the_grand_budapest_hotel.make_rooms(20) | ||
| array.each do |room| | ||
| expect(room).must_be_kind_of Booking::Room | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe "Make_Reservation" do | ||
| before do | ||
| @the_grand_budapest_hotel = build_test_hotel | ||
| start_date = Date.new(2019, 2, 15) | ||
| end_date = Date.new(2019, 2, 20) | ||
| @new_reservation = @the_grand_budapest_hotel.make_reservation(start_date, end_date) | ||
| end | ||
|
|
||
| it "Adds new reservation to all of Hotel's reservations list" do | ||
| expect(@the_grand_budapest_hotel.reservations.length).must_equal 1 | ||
| end | ||
| end | ||
|
|
||
| describe "Find_Reservation" do | ||
| before do | ||
| @the_grand_budapest_hotel = build_test_hotel | ||
|
|
||
| @res_1_start_date = Date.new(2019, 2, 15) | ||
| @res_1_end_date = Date.new(2019, 2, 20) | ||
| @res_1 = @the_grand_budapest_hotel.make_reservation(@res_1_start_date, @res_1_end_date) | ||
|
|
||
| @res_2_start_date = Date.new(2019, 2, 15) | ||
| @res_2_end_date = Date.new(2019, 2, 20) | ||
| @res_2 = @the_grand_budapest_hotel.make_reservation(@res_2_start_date, @res_2_end_date) | ||
|
|
||
| @res_3_start_date = Date.new(2019, 6, 10) | ||
| @res_3_end_date = Date.new(2019, 6, 23) | ||
| @res_3 = @the_grand_budapest_hotel.make_reservation(@res_3_start_date, @res_3_end_date) | ||
| end | ||
|
|
||
| it "returns an array of reservation objects" do | ||
| expect(@the_grand_budapest_hotel.find_reservation(@res_1_start_date, @res_1_end_date)).must_be_kind_of Array | ||
| end | ||
|
|
||
| it "returns an array of the correct length" do | ||
| array = @the_grand_budapest_hotel.find_reservation(@res_1_start_date, @res_1_end_date) | ||
| expect(array.length).must_equal 2 | ||
| end | ||
| end | ||
|
|
||
| describe "Available_Rooms" do | ||
|
|
||
| it "raises an argument if end_date is before start_date" do | ||
| the_grand_budapest_hotel = build_test_hotel | ||
| start_date = Date.new(2019, 2, 20) | ||
| end_date = Date.new(2019, 2, 15) | ||
|
|
||
| expect{the_grand_budapest_hotel.available_rooms(start_date, end_date)}.must_raise ArgumentError | ||
| end | ||
|
|
||
| it "will return an array of rooms that are available given the date range" do | ||
| @the_grand_budapest_hotel = build_test_hotel | ||
| start_date = Date.new(2019, 10, 10) | ||
| end_date = Date.new(2019, 10, 24) | ||
| expect(@the_grand_budapest_hotel.available_rooms(start_date, end_date)).must_be_kind_of Array | ||
| end | ||
|
|
||
| it "raises an exception if there are no rooms available" do | ||
| @the_grand_budapest_hotel = build_test_hotel | ||
| 20.times do | ||
| res_start_date = Date.new(2019, 2, 15) | ||
| res_end_date = Date.new(2019, 2, 20) | ||
| res = @the_grand_budapest_hotel.make_reservation(res_start_date, res_end_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. /Users/devin/Documents/Ada/c12/hotel/test/hotel_test.rb:111: warning: assigned but unused variable - res |
||
| end | ||
| res_21_start_date =Date.new(2019, 2, 15) | ||
| res_21_end_date = Date.new(2019, 2, 20) | ||
| expect{@the_grand_budapest_hotel.available_rooms(res_21_start_date, res_21_end_date)}.must_raise StandardError | ||
| end | ||
| end | ||
| end | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| require_relative 'test_helper' | ||
| require 'date' | ||
|
|
||
| def build_test_reservation | ||
| start_date = Date.new(2019, 2, 15) | ||
|
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 seems like you meant it to be a 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. perhaps a |
||
| end_date = Date.new(2019, 2, 20) | ||
| res_date_range = Booking::DateRange.new(start_date, end_date) | ||
| res_room = Booking::Room.new(5) | ||
| res_total_nights = res_date_range.total_nights | ||
| res_total_cost = res_total_nights * 200 | ||
| reservation = Booking::Reservation.new(res_date_range, res_total_nights, res_total_cost, res_room) | ||
|
||
| end | ||
|
|
||
| describe "Reservation Class" do | ||
| describe "Initialize" do | ||
|
|
||
| it "is an instance of Reservation Class" do | ||
| wes_anderson_reservation = build_test_reservation | ||
| expect(wes_anderson_reservation).must_be_kind_of Booking::Reservation | ||
| end | ||
|
|
||
| it "date_range is an instance of DateRange" do | ||
| wes_anderson_reservation = build_test_reservation | ||
| expect(wes_anderson_reservation.date_range).must_be_kind_of Booking::DateRange | ||
| end | ||
|
|
||
| it "is assigned a room number" do | ||
| wes_anderson_reservation = build_test_reservation | ||
| expect(wes_anderson_reservation.room).must_be_kind_of Booking::Room | ||
| 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.
this is reaching too far into your reservations and date ranges. This should be cleared up by the POODR chapter 4 discussion.