-
Notifications
You must be signed in to change notification settings - Fork 46
Hotel Katherine Fitzpatrick #49
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 all commits
aacd5da
a979ce5
efcef59
86ad84d
e0ea9d2
df3e88a
443c377
40ea09f
70344d9
13439f1
126f1cb
ede760a
2360c00
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,41 @@ | ||
| # #Reservation | ||
| # A ticket stub with reservation details | ||
| #check-in, check-out | ||
| #As an administrator, I can reserve a room for a given date range | ||
| require 'pry' | ||
| require 'date' | ||
| require 'awesome_print' | ||
| require_relative 'room' | ||
|
|
||
| class Reservation | ||
|
|
||
| attr_reader :start_date, :end_date, :room, :total_cost | ||
|
|
||
| def initialize(start_date, end_date, room) | ||
| @start_date = start_date | ||
| @end_date = end_date | ||
| @room = room | ||
| @total_cost = calculate_total_cost | ||
| end | ||
|
|
||
| def calculate_total_cost() | ||
| total_cost = 0 | ||
| number_of_days = ((end_date - start_date).to_i) - 1 | ||
| if number_of_days < 1 | ||
| number_of_days = 1 | ||
| end | ||
| total_cost = number_of_days * 200 | ||
| return 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. indentation |
||
|
|
||
|
|
||
| def date_overlap_check(start_date, end_date) | ||
| @bookings.each do |booking| | ||
| if start_date == booking.start_date && end_date == booking.end_date | ||
| end | ||
| return true | ||
| end | ||
| end | ||
|
|
||
|
|
||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| #Room Class | ||
|
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 class isn't doing much other than providing an |
||
| #The physical space also has nightly rate | ||
|
|
||
| require 'pry' | ||
| require 'awesome_print' | ||
|
|
||
| class Room | ||
|
|
||
| attr_reader :id | ||
|
|
||
| attr_accessor :cost | ||
|
|
||
| def initialize(id, cost = 200 ) | ||
| @id = id | ||
| @cost = cost | ||
| end | ||
| end | ||
|
|
||
|
|
||
|
|
||
| # class HotelMngr | ||
| # @room | ||
| # | ||
| # def book_room(start,end) | ||
| # @room.is_available(start:today) | ||
| # end | ||
| # end | ||
| # | ||
| # class Room | ||
| # def.is_available?(start: start_date, end: end_date) | ||
| # end | ||
| #new_room = Room.new(1, 200) | ||
| #ap new_room | ||
| #write method to list rooms | ||
| #ap self.all | ||
| #concerned with the physical space | ||
| # def self.all | ||
| # CSV.open('./data/customers.csv').map do |customer| | ||
| # id = customer[0].to_i | ||
| # email = customer[1] | ||
| # address = {street: customer[2], city: customer[3], state: customer[4], zip: customer[5]} | ||
| # | ||
| # Customer.new(id,email, address) | ||
| # end | ||
| # end | ||
| # end | ||
| # def room_id_assign | ||
| # rooms = [0...19] | ||
| # room_number = rooms.each_with_index do |index| | ||
| # room_number = room_numbers[i] | ||
| # room_number<<room_numbers | ||
| # binding.pry | ||
| # end | ||
| # end | ||
|
|
||
|
|
||
|
|
||
| #assign id of room from an array of 0-19 | ||
| # def room_id_assign | ||
| # room_a = [0..19] | ||
| # room_a.map do |index| | ||
| # #The index of the array is the room number. | ||
| # room_a = room_a[index] | ||
| # return room_a | ||
| # binding.pry | ||
| # end | ||
| # end | ||
| # #@room_id<<Room.new(room_id,status, cost) | ||
| # | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| # As an administrator, I can access the list of all of the rooms in the hotel | ||
| # As an administrator, I can reserve a room for a given date range | ||
| # As an administrator, I can access the list of reservations for a specific date | ||
| # As an administrator, I can get the total cost for a given reservation | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| #Room Tracker | ||
| # As an administrator, I can access the list of all of the rooms in the hotel | ||
| # As an administrator, I can access the list of reservations for a specific date | ||
| # As an administrator, I can get the total cost for a given reservation | ||
|
|
||
| # The person who manages the reservation book (Takes new reservations and checks availability) | ||
| # | ||
| # List all rooms | ||
| # Keep track room availability | ||
| # Keep track of available dates - dates are in ranges | ||
| # Put requested dates into a date array | ||
| #calculate number of nights = reservation end date - 1 unless only 1 night stayed | ||
| #Room tracker keeps track of rooms and thier associated reservations. | ||
| #Rooms are the key and new_bookings are the associated value. | ||
| #new_bookings are an array - to find available rooms check each room and search the booking date ranges. | ||
| #if date range is free then new room becomes room x | ||
| #calculate total cost here | ||
| #calculate list of reservations | ||
| #creates the objects depends on room and reservation. They don't depend on it. | ||
| require 'pry' | ||
| require 'awesome_print' | ||
| require_relative 'reservation' | ||
| require_relative 'room' | ||
|
|
||
| class Room_Tracker | ||
|
|
||
| def initialize | ||
| # @valid_reservation = {} | ||
| # @valid_reservation[:room] = @@request_array | ||
| @rooms = get_rooms(20) | ||
| @bookings = [] | ||
| #@valid_reservation[:booking] = @@request_array | ||
| end | ||
|
|
||
| def get_rooms(room_count) | ||
| rooms = [] | ||
| room_count.times do |index| | ||
| id = index + 1 | ||
| cost = 200 | ||
| rooms << Room.new(id,cost) | ||
| end | ||
| return rooms | ||
| end | ||
|
|
||
| def list_all_rooms | ||
| return @rooms | ||
| end | ||
|
|
||
| #As an administrator, I can reserve an available room for a given date range | ||
| def make_reservation(start_date, end_date) | ||
| occupied_rooms = [] | ||
| if date_overlap_check(start_date, end_date) == false | ||
| room = @rooms.first | ||
| occupied_rooms << room | ||
| @bookings << Reservation.new(start_date, end_date, room) | ||
| else | ||
| counter = 0 | ||
| while counter <= @rooms.length | ||
| @rooms.each_with_index do |room, i| | ||
| @bookings.each do |booking| | ||
| if room[i] == booking.room | ||
| i + = 1 | ||
| else | ||
| room[i] = room[i] | ||
| occupied_rooms <<room | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
|
|
||
| def find_reservations_by_date(date) | ||
| bookings = [] | ||
| @bookings.each do |booking| | ||
| range = booking.start_date..booking.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. This whole check to see if a Reservation occurs on that date would be wonderful as a helper method in |
||
| if range.cover?(date) | ||
| bookings << booking | ||
| end | ||
| end | ||
| return bookings | ||
| end | ||
|
|
||
| def reservation_total_cost(reservation) | ||
| return reservation.total_cost | ||
| end | ||
|
|
||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #reservation spec | ||
| require_relative 'spec_helper' | ||
|
|
||
| describe Reservation do | ||
|
|
||
| describe "Reservation instantiation" do | ||
| let (:start_date) { Date.parse('2012-02-01') } | ||
| let (:end_date) { Date.parse('2012-02-03') } | ||
| let (:room) { 12 } | ||
| let (:bookings) {[12, 14]} | ||
| describe "#initialize" do | ||
| it "Takes start and end dates" do | ||
|
|
||
| reservation = Reservation.new(start_date,end_date, room) | ||
|
|
||
| expect(reservation).must_respond_to :start_date | ||
| expect(reservation.start_date).must_equal start_date | ||
|
|
||
| expect(reservation).must_respond_to :end_date | ||
| expect(reservation.end_date).must_equal end_date | ||
| end | ||
| end | ||
|
|
||
| describe "I can get the total cost for a given reservation" do | ||
| describe "#calculate_total_cost" do | ||
| it "Takes start and end dates and calculates total cost of room" do | ||
|
|
||
| reservation_test = Reservation.new(start_date, end_date, room) | ||
|
|
||
|
|
||
| expect(reservation_test.calculate_total_cost).must_equal 400 | ||
| end | ||
| end | ||
|
|
||
|
|
||
| end | ||
| 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 are missing an |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| #Room Class | ||
| #The physical space also has nightly rate | ||
|
|
||
| require 'pry' | ||
| require 'awesome_print' | ||
|
|
||
| class Room | ||
|
|
||
| attr_reader :id | ||
|
|
||
| attr_accessor :cost | ||
|
|
||
| def initialize(id, cost = 200 ) | ||
| @id = id | ||
| @cost = cost | ||
| end | ||
| end | ||
|
|
||
|
|
||
|
|
||
| # class HotelMngr | ||
| # @room | ||
| # | ||
| # def book_room(start,end) | ||
| # @room.is_available(start:today) | ||
| # end | ||
| # end | ||
| # | ||
| # class Room | ||
| # def.is_available?(start: start_date, end: end_date) | ||
| # end | ||
| #new_room = Room.new(1, 200) | ||
| #ap new_room | ||
| #write method to list rooms | ||
| #ap self.all | ||
| #concerned with the physical space | ||
| # def self.all | ||
| # CSV.open('./data/customers.csv').map do |customer| | ||
| # id = customer[0].to_i | ||
| # email = customer[1] | ||
| # address = {street: customer[2], city: customer[3], state: customer[4], zip: customer[5]} | ||
| # | ||
| # Customer.new(id,email, address) | ||
| # end | ||
| # end | ||
| # end | ||
| # def room_id_assign | ||
| # rooms = [0...19] | ||
| # room_number = rooms.each_with_index do |index| | ||
| # room_number = room_numbers[i] | ||
| # room_number<<room_numbers | ||
| # binding.pry | ||
| # end | ||
| # end | ||
|
|
||
|
|
||
|
|
||
| #assign id of room from an array of 0-19 | ||
| # def room_id_assign | ||
| # room_a = [0..19] | ||
| # room_a.map do |index| | ||
| # #The index of the array is the room number. | ||
| # room_a = room_a[index] | ||
| # return room_a | ||
| # binding.pry | ||
| # end | ||
| # end | ||
| # #@room_id<<Room.new(room_id,status, cost) | ||
| # | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| # As an administrator, I can access the list of all of the rooms in the hotel | ||
| # As an administrator, I can reserve a room for a given date range | ||
| # As an administrator, I can access the list of reservations for a specific date | ||
| # As an administrator, I can get the total cost for a given reservation |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| require_relative 'spec_helper' | ||
|
|
||
| describe Room do | ||
|
|
||
| describe "Room instantiation" do | ||
| describe "#initialize" do | ||
| it "Takes cost and id" do | ||
| room = Room.new(id = 1, cost = 200) | ||
|
|
||
| expect(room).must_respond_to :id | ||
| expect(room.id).must_equal id | ||
|
|
||
| expect(room).must_respond_to :cost | ||
| expect(room.cost).must_equal cost | ||
|
|
||
| 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 would also suggest you add a method to tell if two reservations overlap, and another to tell if a reservation occurs on a specific date.