Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a2c2c4d
Build design scaffolding
Jul 25, 2019
22cee60
Merge branch 'master' of github.com:AdaGold/hotel into dpr/c12-scaffo…
Jul 25, 2019
df7c9b8
Update notes about design scaffolding
Jul 25, 2019
a673135
Add interface test for HotelController#available_rooms
Jul 25, 2019
d5489c4
Correct branch name for merge instructions
Jul 29, 2019
e9ec9b5
Merge pull request #20 from AdaGold/dpr/c12-scaffolding
Jul 29, 2019
eaa813b
Instance of time: pass, duration calculated correctly: pass
Sep 7, 2019
461934c
Rooms populated correctly in array
Sep 7, 2019
b3ccd76
Calculates cost correctly
Sep 7, 2019
f4407a1
Generates room number: pass
Sep 7, 2019
5a2572b
Changed reservation class - initalize includes dates
Sep 8, 2019
aa59da5
Corrections to duration - 53% coverage
Sep 8, 2019
9a7b81f
Creates accurate instance of cost: passed
Sep 8, 2019
0a26738
Creates reservation (assigns room, check_in/out, duration, price)
Sep 8, 2019
25dfa88
Current state
Sep 12, 2019
de9223d
Merge scaffolding - full restructure
Sep 21, 2019
aa7343a
Room list created, HotelController test created
Sep 23, 2019
bb3a694
Constructor for DateRange written, DateRange test file created
Sep 23, 2019
213f5ca
Updated all tests w/ copy/paste from specs folder
Sep 24, 2019
2e4084a
Implemented error raised for invalid date
Sep 24, 2019
fa65274
Comment out error for invalid date, reserve_room method created/passes
Sep 24, 2019
de84844
Created @night in date_range, implemented cost method in reservation.…
Sep 24, 2019
1c4b615
Reimplemented raise argument error, cleaned up spacing. Still Argumen…
Sep 24, 2019
fc1657e
Changed nights from instance to local variable in cost method, added …
Sep 24, 2019
d866cee
Created reservation_list instance variable, implemented reservations …
Sep 24, 2019
2c14392
Fixed bracket/parens for error tests, now passing
Sep 24, 2019
75f2ad6
Removed incorrect/unnecessary attr_writer/instance variable for night…
Sep 24, 2019
1b15dd2
Made method that assigns room number based on reservations within res…
Sep 24, 2019
16220ea
Removed unnecessary nights attr_accessor from hotel_controller, added…
Sep 24, 2019
351c237
Updated hotel_controller to iterate properly
Sep 25, 2019
b6165af
Corrected available_rooms iteration (again) and fixed room assignment…
Sep 25, 2019
5e6efb6
Created overlap method and finished writing corresponding tests - all…
Sep 27, 2019
11b1026
Design activity Part 1
Sep 29, 2019
692b6c2
Design activity Part 2
Sep 29, 2019
abbbacf
Refactored available rooms method
Sep 29, 2019
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
32 changes: 32 additions & 0 deletions .history/lib/reservation_20190921132905.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<<<<<<< HEAD
require_relative '../lib/time'
require_relative '../lib/service'



class Reservation
attr_accessor :room, :price, :duration, :cost, :check_in, :check_out, :reservations


def initialize(check_in, check_out)
@check_in = check_in
@check_out = check_out
@duration = Dates.new.reserve_time(check_in, check_out)
@cost = Service.new.room_cost(@duration)
@room = rand(1..20)
end


=======
module Hotel
class Reservation
# Feel free to change this method signature as needed. Make sure to update the tests!
def initialize(start_date, end_date, room)
end

def cost
return 3
end
end
>>>>>>> origin/design-scaffolding
end
15 changes: 15 additions & 0 deletions .history/lib/reservation_20190921134233.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


=======
module Hotel
class Reservation
# Feel free to change this method signature as needed. Make sure to update the tests!
def initialize(start_date, end_date, room)
end

def cost
return 3
end
end
>>>>>>> origin/design-scaffolding
end
12 changes: 12 additions & 0 deletions .history/lib/reservation_20190921134326.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

module Hotel
class Reservation
# Feel free to change this method signature as needed. Make sure to update the tests!
def initialize(start_date, end_date, room)
end

def cost
return 3
end
end
end
19 changes: 19 additions & 0 deletions design-activity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Evaluation Responsibility:

1. A includes the classes CartEntry, ShoppingCart, and Order. B has the same classes.

2. CartEntry is a class that initializes unit_price and quantity. Shopping cart initializes an array of entries, and Order creates a new instance of ShoppingCart and stores it in the instance variable cart.
In implementation A, CartEntry unit_price and quantity are shared with Order to return total price. Shopping cart shares entries with Order, which is used in the method total_price. Order creates a new instance of shopping cart. In implementation B, Order relies on the information stored in CartEntry and ShoppingCart to make a new instance of cart. In Implementation B, the methods for that class are created within the class then accessed by creating an instance of that class.

3. In Implementation A, CartEntry has no methods, Shopping cart has no methods, and Order has a total price method using the instance variables from CartEntry, and the instance of cart from Order. In Implementation B, CartEntry has a method of price, calculated by multiplying the instances of unit and quantity. Shopping cart has a separate method for price, which adds the price of each entry and creates a total sum for entries. Order has the method total_price which returns the price for an instance of cart, then returns a total price including sales tax. The second implementation uses instances of another class rather than instance variables stored within that class.

4. For Implementation A, the price is computed in Order. Total_price is directly manipulating instance variable of other classes. In Implementation B, each lower level class creates its own instance of price.

5. For items bought in bulk, I think Implementation B would be easier to modify, because price could be altered in the lower level classes fairly easily rather than having to change the entire method in Implementation A's Order class.

6. The implementation that better adheres to the single responsibility principle (and is more loosely coupled) is Implementation B.


Revisiting Hotel:

In Hotel Controller, the available rooms method is creating a new instance of the class DateRange instead of taking instances of DateRange. I may be able to simply remove that portion of the code, since it looks like it may be redundant in relation to the rest of the code in that method. If not, the method should be written to be taking instance variables in the until loop rather than local variables. After looking at the code, I think that it's a flaw in the original intention of the design, rather than an area that needs to be refactored.
38 changes: 38 additions & 0 deletions design-scaffolding-notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Hotel Design Scaffolding

## Purpose

This scaffolding is intended for students who are feeling overwhelmed by the open-ended nature of the Hotel project. Its goal is to answer some of the initial questions about how project files should be laid out, so that students can focus on designing the object interactions and complex Ruby logic that are the core learning goals of the project. The hope is to do so without removing too much of the interesting design work.

This document and the associated code is intended to be student-facing - if you have a student you think would benefit from this, send them a link!

### What it includes

- Three class stubs, `HotelController`, `Reservation` and `DateRange`
- Stubs for public methods of each class from waves 1 and 2, as described in the user stories
- "Interface" tests for each class method that invoke it with the right parameters and verify the return type
- Full test stubs for the `DateRange` class

### What it does not include

- Opinions about how classes should interact or data should be stored
- Opinions about whether there should be a `Room` class, or whether it should know about `Reservation`s
- Private helper methods to keep code organized

Students should feel free to modify any code as they see fit, including changing method signatures, adding new classes and methods, reordering things, not looking at the `DateRange` tests because they want to give it a shot on their own, etc.

## How to use this code

Design scaffolding code lives on the `design-scaffolding` branch.

You can use this code either as inspiration, or as a starting point. If using it as an inspiration, it follows our standard project layout, with product code under `lib/` and tests under `spec/`.

If you choose to use the code on this branch as a starting point, follow these steps to start your project:

```
$ git clone <paste forked repo URL>
$ cd hotel
$ git merge origin/design-scaffolding
```

You can try to merge in the design scaffolding after you've started, but you'll probably end up with merge conflicts. See an instructor if you're not able to resolve them yourself.
46 changes: 46 additions & 0 deletions lib/date_range.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

require 'pry'

module Hotel
class DateRange

attr_accessor :start_date, :end_date

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


if start_date == nil || end_date == nil
raise ArgumentError.new
elsif end_date <= start_date
raise ArgumentError.new
end
end

def nights
nights = (end_date - start_date) - 1
nights = nights.to_i
end



def overlap?(range)
if range.end_date > @start_date && range.end_date < @end_date
return true
elsif range.start_date < @start_date && range.end_date > @end_date
return true
elsif range.start_date == @start_date
return true
else
return false
end

end

# def include?(date)
# return false
# end

end
end
94 changes: 94 additions & 0 deletions lib/hotel_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
require_relative 'date_range'
require_relative 'reservation'
require 'pry'

module Hotel
class HotelController

# does this need to be accessor? idk, look it up

attr_accessor :reservation_list, :rooms, :reservation

# Wave 1
def initialize
@rooms = (1..20).to_a
@reservation_list = []
@reservation = reservation
end

# may be complete nonsense, need to test with more than one occurence, but will return first index for empty list
def reserve_room(start_date, end_date)

current_room = ()
if @reservation_list.empty? == true
current_room = rooms.shift
elsif @reservation_list.empty? == false
@reservation_list.include?(start_date)
count = @reservation_list.count(start_date)
current_room = rooms[count - 1]
end


room = current_room
range = Hotel::DateRange.new(start_date, end_date)
start_date = range.start_date
end_date = range.end_date
nights = range.nights

# if the range has overlapping dates, then it will return true
# if the range returns true

reservation = Reservation.new(start_date, end_date, nights, room)

# if @reservations_list.overlap?(range)
# raise ArgumentError.new
# end

@reservation_list << reservation
return reservation
end

# possible trickery, reassess when more reservations are generated?
def reservations(date)
reservation_list.each do |index, date|
if reservation_list[index].include?(date)
print reservation_list[index]
end
end
end

# Wave 2
def available_rooms(start_date, end_date)
# range = Hotel::DateRange.new(start_date, end_date)
# start_date = range.start_date
# end_date = range.end_date
# nights = range.nights
length = end_date - start_date
check = 1

until check == length do
if @reservation_list.empty? == false
@reservation_list.each do
@reservation.include?(@start_date)
rooms.delete(@reservation.room)
end
elsif @reservation_list.empty?
break
end
@start_date + 1
check += 1
end
return rooms
end

end

end
# if the reservation list includes that date
# check for room numbers for that date
# delete that room number from a generic list of rooms
# iterate to next date (nights)


# start_date and end_date should be instances of class Date

19 changes: 19 additions & 0 deletions lib/reservation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require_relative 'date_range'


module Hotel
class Reservation

attr_reader :room, :nights
# Feel free to change this method signature as needed. Make sure to update the tests!
def initialize(start_date, end_date, nights, room)
@room = room
@nights = nights
end

def cost
price = 200
cost = price * nights
end
end
end
78 changes: 78 additions & 0 deletions spec/date_range_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
require_relative "spec_helper"

describe Hotel::DateRange do
describe "consructor" do
it "Can be initialized with two dates" do
start_date = Date.new(2017, 01, 01)
end_date = start_date + 3

range = Hotel::DateRange.new(start_date, end_date)

expect(range.start_date).must_equal start_date
expect(range.end_date).must_equal end_date
end

xit "is an an error for negative-lenght ranges" do
end

xit "is an error to create a 0-length range" do
end
end

describe "overlap?" do
before do
start_date = Date.new(2017, 01, 01)
end_date = start_date + 3

@range = Hotel::DateRange.new(start_date, end_date)
end

it "returns true for the same range" do
start_date = @range.start_date
end_date = @range.end_date
test_range = Hotel::DateRange.new(start_date, end_date)

expect(@range.overlap?(test_range)).must_equal true
end

xit "returns true for a contained range" do
end

xit "returns true for a range that overlaps in front" do
end

xit "returns true for a range that overlaps in the back" do
end

xit "returns true for a containing range" do
end

xit "returns false for a range starting on the end_date date" do
end

xit "returns false for a range ending on the start_date date" do
end

xit "returns false for a range completely before" do
end

xit "returns false for a date completely after" do
end
end

xdescribe "include?" do
it "reutrns false if the date is clearly out" do
end

it "returns true for dates in the range" do
end

it "returns false for the end_date date" do
end
end

xdescribe "nights" do
it "returns the correct number of nights" do
end
end
end
Loading