Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 0 additions & 50 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,50 +0,0 @@
*.gem
*.rbc
/.config
/coverage/
/InstalledFiles
/pkg/
/spec/reports/
/spec/examples.txt
/test/tmp/
/test/version_tmp/
/tmp/

# Used by dotenv library to load environment variables.
# .env

## Specific to RubyMotion:
.dat*
.repl_history
build/
*.bridgesupport
build-iPhoneOS/
build-iPhoneSimulator/

## Specific to RubyMotion (use of CocoaPods):
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# vendor/Pods/

## Documentation cache and generated files:
/.yardoc/
/_yardoc/
/doc/
/rdoc/

## Environment normalization:
/.bundle/
/vendor/bundle
/lib/bundler/man/

# for a library or gem, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# Gemfile.lock
# .ruby-version
# .ruby-gemset

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, why did you delete the contents of this file?

10 changes: 10 additions & 0 deletions lib/customer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module HotelBooking
class Customer
attr_reader :id, :name

def initialize(id:, name:)
@id = id
@name = name
end
end
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No tests! Maybe this is a result of realizing that our project doesn't require Customers being implemented, so it was hard to understand what to test a Customer to do :)

29 changes: 29 additions & 0 deletions lib/date_range.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require "date"
require "pry"

module DateRange
class DateRange
attr_accessor :start_date, :end_date

def initialize(start_date, end_date)
@start_date = start_date
@end_date = end_date

if @end_date <= @start_date
raise ArgumentError.new "Invaid dates provided"
end
end

def overlap?(other)
return other.start_date == @start_date && other.end_date == @end_date
end

def include?(date)
return false
end

def nights
return @end_date - @start_date.to_i
end
end
end
37 changes: 37 additions & 0 deletions lib/duration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require "date"

module HotelBooking
class Duration
attr_reader :start_date, :end_date

def initialize(start_date:, end_date:)
@start_date = convert_to_date(start_date)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use Date.parse(start_date) instead of using the convert_to_date method?

@end_date = convert_to_date(end_date)

if @end_date <= @start_date
raise ArgumentError.new "Invaid dates provided"
end
end

def convert_to_date(date_str)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method doesn't get tested!

date_arr = date_str.split("-")
year = date_arr[0].to_i
month = date_arr[1].to_i
date = date_arr[2].to_i

return Date.new(year, month, date)
end

def get_nights()
night_count = (@start_date...@end_date).count
return night_count
end

def overlap?(duration)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method never gets tested OR used in any other file. Can we delete it, or can we refactor our code to use it?

if @start_date <= duration.end_date && duration.start_date <= @end_date
return false
end
return true
end
end
end
5 changes: 5 additions & 0 deletions lib/experiment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# require_relative 'date-range'
# require_relative 'reservation'

# one_reservation = Reservation.new(id:1, customer_id:2, room:303, duration:3, total_cost:300)
# date_range = DateRange.new(id:, start_day:, end_day:)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to delete this file before project submission

101 changes: 101 additions & 0 deletions lib/hotel.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
require_relative "room"
# require_relative "customer"
require_relative "duration"
require_relative "reservation"
require_relative "date_range"

module HotelBooking
class Hotel
TOTAL_ROOMS = 20
attr_reader :id, :rooms, :reservations, :vacancy
attr_accessor :customers

def initialize(id:, name:)
@id = id
@name = name
@rooms = []
@reservations = []
@customers = []
@vacancy = true

make_room
end

def make_room()
TOTAL_ROOMS.times do |index|
room = Room.new(id: index + 1, number: index + 1, availability: true, reservation: nil)
@rooms << room
end
end

def get_total_rooms()
return @rooms.length
end

def add_customer(customer)
# customer = Customer.new(id: 1, name: "one")
@customers << customer
end

def find_customer(id)
customer = @customers.find { |customer| customer.id == id }
return customer
end

#list of rooms that are not reserverd
def get_availbale_rooms(date)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"available" is mispelled in your method name-- watch out!

available_rooms = @rooms.find_all { |room| room.availability == true }
# rooms_date_range = available_rooms.find_all { |room| (date >= room.reservation.duration.start_date && date <= room.reservation.duration.end_date) }
return available_rooms
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method doesn't use the date parameter. Why not? What does it mean for a room to have availability? Isn't the requirement to find rooms that are available for a specific date? What does it mean when a room is "available"?

end

def get_reservation(date)
reservations_for_date = []
@reservations.each do |res|
if date >= res.duration.start_date && date <= res.duration.end_date
reservations_for_date << res
end
end
# reservation = @reservations.find { |res| res.start_date == date }
return reservations_for_date
end

def make_reservation(customer_id, start_date, end_date)
room_to_reserve = @rooms.find { |room| room.availability }

room_index = @rooms.find_index(room_to_reserve)

duration = Duration.new(
start_date: start_date, end_date: end_date,
)
reservation = Reservation.new(
id: 1,
customer_id: customer_id,
room: room_index,
duration: duration,
)
room_to_reserve.availability = false
room_to_reserve.reservation = reservation
@rooms[room_index] = room_to_reserve
@reservations << reservation
end

def get_reservation_cost(res_index)
# reservation_cost = Reservation.new(id: 1, cost:)
res = @reservations[res_index]
total_cost = 0
if res != nil
total_cost = res.get_total_cost()
end
return total_cost
end

def reserve_room_on(cust_id, room_number, start_date, end_date)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between reserve_room_on and make_reservation? How can we change the name of these methods so that they are more clear about what they do and what the differences are?

room = @rooms.find { |room| room.number == room_number }
if room.availability == false || room.reservation != nil
raise ArgumentError.new "This room is already reserved"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestion: Instead of an ArgumentError, could we raise a more specific kind of error, or create a new custom Error class?

end
make_reservation(cust_id, start_date, end_date)
end
end
end
23 changes: 23 additions & 0 deletions lib/main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "pry"
require_relative "hotel"
require_relative "customer"

module HotelBooking
def HotelBooking.main
# create a hotel instance
hotel = Hotel.new(id: 1, name: "My Hotel")

# check what our hotel looks
customer_1 = Customer.new(
id: 1, name: "One",
)

hotel.add_customer(customer_1)

hotel.make_reservation(1, 10, "2019-9-3", "2019-9-15")

# binding.pry
end
end

HotelBooking.main
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to delete this file before project submission

19 changes: 19 additions & 0 deletions lib/reservation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module HotelBooking
class Reservation
COST_PER_NIGHT = 200
attr_reader :id, :customer_id, :room, :duration, :cost_per_night

def initialize(id:, customer_id:, room:, duration:, cost_per_night: COST_PER_NIGHT)
@id = id
@customer_id = customer_id
@room = room
@cost_per_night = cost_per_night
@duration = duration
end

def get_total_cost()
total_cost = @duration.get_nights() * @cost_per_night
return total_cost
end
end
end
17 changes: 17 additions & 0 deletions lib/room.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module HotelBooking
class Room
attr_reader :id, :number, :cost
attr_accessor :availability, :reservation

def initialize(id:, number:, cost: 200.0, availability:, reservation:)
@id = id
@number = number
@cost = cost,
@availability = availability,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are there commas here and the line above? Also, watch your indentation!

@reservation = reservation
end

def total_cost()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method isn't implemented or used anywhere else, so feel free to delete this method

end
end
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have no tests for Room :(

Empty file added test/customer_test.rb
Empty file.
32 changes: 32 additions & 0 deletions test/duration_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require_relative "test_helper"

describe HotelBooking::Duration do
describe "duration test" do
it "raise exception when an invalid date range is provided" do
expect {
HotelBooking::Duration.new(
start_date: "2019-02-01",
end_date: "2019-01-01",
)
}.must_raise ArgumentError
end
end
describe "" do
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to add a description to your describe blocks. If you can't find a good name, then maybe you need to think about how you're organizing your code

before do
@duration = HotelBooking::Duration.new(
start_date: "2019-09-01",
end_date: "2019-09-05",
)
end

it "get nights" do
start_date = Date.new(2019, 9, 1)
end_date = Date.new(2019, 9, 5)
count = (start_date...end_date).count
night_count = @duration.get_nights()
expect(night_count).must_equal count
end
end
end
# describe "cost" do
# it "a"
Loading