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
6 changes: 6 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
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{^spec/spec_helper\.rb$}) { 'spec' }
end
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Reinforce and practice all of the Ruby and programming concepts we've covered in

This is a [stage 3](https://github.com/Ada-Developers-Academy/pedagogy/blob/master/rule-of-three.md), individual project.

This project is due before class on **Monday September 10th**

## Introduction

Expand Down
9 changes: 9 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'rake/testtask'

Rake::TestTask.new do |t|
t.libs = ['lib']
t.warning = true
t.test_files = FileList['specs/*_spec.rb']
end

task default: :test
38 changes: 38 additions & 0 deletions design-activity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
1. What classes does each implementation include? Are the lists the same?
implementation a: CartEntry, ShoppingCart, Order.
implementation b: CartEntry, ShoppingCart,Order.
Yes, the lists are the same.

2. Write down a sentence to describe each class.
implementation a:
CartEntry- initialize cart with unit_price and quantity as local variables.
ShoppingCart- initialize cart with entries as local variable containing an empty array.
Order- define SALES_TAX, initialize order with a new instance of @cart, method for calculating the prices
by iterating through @cart entries, calling unit_price on the entry, and returning the total including sales tax.
implementation b:
CartEntry- initialize cart with unit_price and quantity as local variables,
and a method for calling price.
ShoppingCart- initialize cart as a local variable containing an empty array.
Order- define SALES_TAX, define subtotal by calling price on @cart, and returning the total including sales tax.

3. How do the classes relate to each other?


4. What data does each class store? How (if at all) does this differ between the two implementations?



5. What methods does each class have? How (if at all) does this differ between the two implementations?


6. Consider the Order#total_price method. In each implementation:
Is logic to compute the price delegated to "lower level" classes like ShoppingCart and CartEntry, or is it retained in Order?
Does total_price directly manipulate the instance variables of other classes?


7. If we decide items are cheaper if bought in bulk, how would this change the code? Which implementation is easier to modify?

8. Which implementation better adheres to the single responsibility principle?


** Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled? implementation a
10 changes: 10 additions & 0 deletions lib/.keep
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
User Stories
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
Constraints
The hotel has 20 rooms, and they are numbered 1 through 20
Every room is identical, and a room always costs $200/night
The last day of a reservation is the checkout day, so the guest should not be charged for that night
For this wave, any room can be reserved at any time, and you don't need to check whether reservations conflict with each other (this will come in wave 2!)
35 changes: 35 additions & 0 deletions lib/date_range.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class DateRange

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The idea for this class is a really good idea, but the implementation doesn't make sense.

attr_reader :start_date, :end_date

# def res_start(start_time = '11:00'.strftime('%k%M'))
# @res_start = res_start
# end
# def res_end(end_time = '15:00'.strftime('%k%M'))
# @res_end = res_end
# end

# def start_date
# @start_date = DateTime.new
# end
#
# def end_date
# @end_date = DateTime.new
# end

def initialize(start_date, end_date)
unless end_date > start_date
raise ArgumentError.new("Your dates are incorrect)")
end
@start_date = start_date.DateTime.new
@end_date = end_date.DateTime.new
end

def contains(date)
return date >= @start_date && date < @end_date
end

def nights
return @end_date - @start_date
end

end
70 changes: 70 additions & 0 deletions lib/hotel_admin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<<<<<<< HEAD
# require_relative 'room.rb'
# require_relative 'reservation.rb'
#
#
# module Hotel
# class Admin
# attr_accessor :rooms
# def initialize
# @rooms = Hotel::Room.create_rooms
# end
#
#
# def new_reservation(room_number, start_date_time, end_date_time, cost)
# @room_number = room_number
# @start_date_time = start_date_time
# @end_date_time = end_date_time
# @cost = cost
# end
# @new_reservation
#
# def check_room_status
# @booked_rooms = []
# @open_rooms = []
# @rooms.each do |number, status|
# if :room_status == :Available
# status = :Unavailable
# @booked_rooms << room
# elsif :room_status == :Available
# @open_rooms << room
# end
# @booked_rooms
# @open_rooms
# end
# end
# end
#
# end
# end
=======
require_relative 'room.rb'
# require_relative 'reservation.rb'
# require_relative 'hotel_admin.rb'

module Hotel
class Admin
attr_accessor :rooms
def initialize
@rooms = Hotel::Room.create_rooms
end

def self.check_room_status
@booked_rooms = []

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since this is a class method, you shouldn't need instance variables.

@open_rooms = []
@rooms.each do |number, status|
if :room_status == :Available
status = :Unavailable

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A room won't be just available or unavailable. A room's availability depends on the date.

@booked_rooms << room
elsif :room_status == :Available
@open_rooms << room
end
@booked_rooms
@open_rooms
end
end
end


end
>>>>>>> 7ad404c6cf9267bef449cee230493c6008ca966b
104 changes: 104 additions & 0 deletions lib/reservation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# create module for reservations to hold classes
require 'pry'
<<<<<<< HEAD
require_relative 'date_range'
module Hotel

class ReserveRoom < DateRange
attr_reader :room_number
attr_accessor :cost

def initialize(start_date,end_date, cost)
=======
require_relative 'hotel_admin.rb'
module Reservation

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You should put each class in the same module. Grouping the classes into a common module is how we normally organize classes in our project.


class ReserveRoom

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would probably name this class Reservation

attr_accessor :room_status, :start_date, :end_date, :cost, :res_id

def initialize( start_date_time, end_date_time, res_id, cost = 200)
@start_date = DateTime.strptime(start_date_time + " 15:00", "%m/%d/%y %H:%M")
@end_date = DateTime.strptime(end_date_time + " 11:00", "%m/%d/%y %H:%M")
@res_id = res_id
>>>>>>> 7ad404c6cf9267bef449cee230493c6008ca966b
@cost = cost
super(start_date, end_date)
end

<<<<<<< HEAD
def self.create_reservation
end

def calculate_cost
nights = @end_date - @start_date
@cost = nights * 200.to_f
end

def available_rooms
dates = DateRange.new(start_date, end_date)
available_rooms = @rooms
end
=======
# def self.create_reservation
# end

def calculate_cost
num_nights = (end_date - start_date).to_i
@room_cost = (num_nights + 1) * 200.to_f
end

# def check_room_status
# @rooms.each do |status|
# if :room_status == :Available
# puts 'Room is Available.'
# elsif :room_status == :Unavailable
# puts 'Room is Unavailable.'
# end
# end
# end
>>>>>>> 7ad404c6cf9267bef449cee230493c6008ca966b
end
end

# def check_room_status
# @rooms.each do |status|
# if :room_status == :Available
# puts 'Room is Available.'
# elsif :room_status == :Unavailable
# puts 'Room is Unavailable.'
# end
# end
# end
# end
# end
#
#
# open_rooms = []
# reserved_rooms = []
# def lists_booked_rooms
# start_date = Date.parse('20/09/2018')
# end_date = Date.parse ('30/09/2018')
# date_range = (start_date..end_date)
# @all_rooms.to_a.each do |room|
# @booked_rooms.to_a.each do |room|
# if all_rooms.room_number != booked_rooms.room_number
# open_rooms << room
# elsif all_rooms.room_number == booked_rooms.room_number
# reserved_rooms << room
# end
# end
# end
# end

# Two date ranges *do* overlap if range A compared to range B:
# - Same dates
# - Overlaps in the front
# - Overlaps in the back
# - Completely contained
# - Completely containing
#
# Two date ranges are *not* overlapping if range A compared to range B:
# - Completely before
# - Completely after
# - Ends on the checkin date
# - Starts on the checkout date
51 changes: 51 additions & 0 deletions lib/room.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require_relative 'reservation'

module Hotel
class Room
attr_reader :room_number
attr_accessor :status

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A room won't have a set status. The status will depend on the date as well.


def initialize(room_number, status = :Available)
@room_number = room_number
@status = status
end
def self.create_rooms
@all_rooms = [ ]
room_number = 0
20.times do
room_number += 1
@all_rooms << Room.new(room_number)
end
return @all_rooms
end
def self.list_all_rooms
@all_rooms = self.create_rooms
return @all_rooms
end
end
end
# module Hotel
# # create new class of Room, to create the block of rooms
# class Room
# attr_accessor :rooms, :room_cost, :reservations
#
#
# def initialize
# @rooms = rooms
# @room_cost = 200
# @reservations = []
# @blocks = []
# end
#
# def create_rooms
# 20.times do
# @all_rooms << Room.new
# end
# puts @all_rooms
# end
#
# def room_list
# return @all_rooms
# end
# end
# end
10 changes: 10 additions & 0 deletions specs/date_range_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require_relative 'spec_helper'

describe 'DateRange Class' do
describe 'initialize date_range' do
it 'is an instance of date_range' do
test_date_range = DateRange.new('09/20/18', '09/22/18')
expect(test_date_range).must_be_kind_of DateRange
end
end
end
49 changes: 49 additions & 0 deletions specs/hotel_admin_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require_relative 'spec_helper'
<<<<<<< HEAD
# require_relative '../lib/hotel_admin.rb'
=======
require_relative '../lib/hotel_admin.rb'
>>>>>>> 7ad404c6cf9267bef449cee230493c6008ca966b


describe 'Admin Class' do
describe 'initialize Admin' do
it 'it is an instance of Admin' do
@test_admin = Hotel::Admin.new
expect(@test_admin).must_be_kind_of Hotel::Admin
end
end

<<<<<<< HEAD
it 'reserves a room for a specific date' do
@new_reservation = Hotel::New_Reservation.new_reservation.new
expect(@new_reservation).must_be_kind_of Hotel::Reservation
end

=======
>>>>>>> 7ad404c6cf9267bef449cee230493c6008ca966b
it 'creates a list of twenty rooms' do
@rooms = Hotel::Room.create_rooms
expect(@rooms.length).must_equal 20
end

<<<<<<< HEAD
it 'can check the status of a room' do
@test_room = Hotel::Admin.new
expect(@test_room.check_room_status).must_equal Unavailable
end
it 'creates a reservation' do
test_reservation = Hotel::Admin.create_reservation.new( '09/20/18', '09/22/18', 1)
expect(test_reservation).must_be_kind_of Reservation::ReserveRoom
end
=======
# it 'can check the status of a room' do
# @test_room = Hotel::Admin.new
# expect(@test_room.check_room_status).must_equal Unavailable
# end
# it 'creates a reservation' do
# test_reservation = Hotel::Admin.create_reservation.new( '09/20/18', '09/22/18', 1)
# expect(test_reservation).must_be_kind_of Reservation::ReserveRoom
# end
>>>>>>> 7ad404c6cf9267bef449cee230493c6008ca966b
end
Loading