-
Notifications
You must be signed in to change notification settings - Fork 49
Sara - Branches #36
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?
Sara - Branches #36
Changes from all commits
aeb0cd4
869c586
fdb9e0b
5e94fcd
ee9410f
3fe4ffc
26b8480
27258d5
8397e45
155f10a
3da5913
5f1c8c5
b65c14f
fcbc2c5
adc7ec1
38c1908
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,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 | ||
| 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 | ||
|
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. 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 :) |
||
| 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 |
| 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) | ||
|
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. Could we use |
||
| @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) | ||
|
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 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) | ||
|
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 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 | ||
| 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:) | ||
|
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. Feel free to delete this file before project submission |
||
| 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) | ||
|
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. "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 | ||
|
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 doesn't use the |
||
| 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) | ||
|
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. What is the difference between |
||
| room = @rooms.find { |room| room.number == room_number } | ||
| if room.availability == false || room.reservation != nil | ||
| raise ArgumentError.new "This room is already reserved" | ||
|
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. Minor suggestion: Instead of an |
||
| end | ||
| make_reservation(cust_id, start_date, end_date) | ||
| end | ||
| end | ||
| end | ||
| 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 | ||
|
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. Feel free to delete this file before project submission |
||
| 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 |
| 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, | ||
|
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. Why are there commas here and the line above? Also, watch your indentation! |
||
| @reservation = reservation | ||
| end | ||
|
|
||
| def total_cost() | ||
|
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 isn't implemented or used anywhere else, so feel free to delete this method |
||
| 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 have no tests for |
||
| 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 | ||
|
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. Don't forget to add a description to your |
||
| 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" | ||
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.
Hm, why did you delete the contents of this file?