-
Notifications
You must be signed in to change notification settings - Fork 299
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
Time - Haben #38
Open
HabenFoto
wants to merge
23
commits into
AdaGold:master
Choose a base branch
from
HabenFoto:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Time - Haben #38
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
a2c2c4d
Build design scaffolding
22cee60
Merge branch 'master' of github.com:AdaGold/hotel into dpr/c12-scaffo…
df7c9b8
Update notes about design scaffolding
a673135
Add interface test for HotelController#available_rooms
d5489c4
Correct branch name for merge instructions
e9ec9b5
Merge pull request #20 from AdaGold/dpr/c12-scaffolding
b454eb1
spec -> test
kaidamasaki 5717d12
conforms the text to imply more of an activity
tildeee e738121
direct link to this repo and branch
tildeee 2b3cd3a
Merge remote-tracking branch 'origin/design-scaffolding'
HabenFoto fa73fb6
added tests
HabenFoto d06db3f
changed method names
HabenFoto 34aefad
added methods
HabenFoto 0fcbfb7
wrote methods
HabenFoto 1a101e3
wrote methods
HabenFoto 1f69b45
wave -2- All the tests in date_range_test are passing
HabenFoto 0cbd2f9
edited find_available_rooms
HabenFoto 16bdf27
modified date_range overlap method
HabenFoto 75b7894
added tests to reservation_test
HabenFoto d004a72
added attr_readers to reservation
HabenFoto e9ca15a
arranged simplcov in the right order
HabenFoto eaf32b8
added more tests
HabenFoto c54f629
completed wave 2
HabenFoto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,3 +48,4 @@ build-iPhoneSimulator/ | |
|
||
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: | ||
.rvmrc | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Hotel Design Scaffolding | ||
|
||
## How to Read This Scaffolding to Create a Second Draft | ||
|
||
This scaffolding is one solution that answers some of the initial questions about how project files can be laid out. | ||
|
||
Use [this view of our branch on GitHub.com](https://github.com/AdaGold/hotel/tree/design-scaffolding) to explore the files that exist on this repo. | ||
- What classes exist? | ||
- Why? What are they named, what do they represent, and what state and behavior do they have? | ||
- What tests exist? | ||
- What parts of this design inspires you, and you want to steal? | ||
- What parts of this design are you unsure about, and need to consider again later? | ||
- What parts of this design do you think you can do without? | ||
|
||
Spend **no more than 1 hour** answering those questions and adjusting your project's first draft design. After one hour, get started; don't forget that a useful skill for the programmer is the ability to get started, and adjust in small ways often. | ||
|
||
### 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 `test/`. | ||
|
||
If you choose to use the code on this branch as a starting point, you can either: | ||
|
||
1. Copy and paste each file from this project into your existing `hotel` folder | ||
2. Or start your project anew with the following steps: | ||
|
||
``` | ||
$ git clone <paste forked repo URL> | ||
$ cd hotel | ||
$ git merge origin/design-scaffolding | ||
``` | ||
|
||
- Note: 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Hotel | ||
class DateRange | ||
attr_accessor :start_date, :end_date | ||
|
||
def initialize(start_date, end_date) | ||
# if start date is on or after end Date, raise an exception | ||
if start_date >= end_date | ||
raise ArgumentError, " Invalid Date Range." | ||
|
||
end | ||
|
||
@start_date = start_date | ||
@end_date = end_date | ||
end | ||
# check if date selected overlaps with the date_range | ||
def overlap?(new_start_date, new_end_date) | ||
return(start_date <= new_end_date && end_date >= new_start_date) | ||
end | ||
# check if new_date is between start_date and end_date | ||
def include?(new_date) | ||
return start_date <= new_date && end_date > new_date | ||
end | ||
|
||
def nights | ||
return end_date - start_date | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
module Hotel | ||
class HotelController | ||
# Wave 1 | ||
attr_reader :reservations, :rooms | ||
|
||
# I can access the list of all of the rooms in the hotel | ||
def initialize | ||
@reservations = [] | ||
@rooms = [] #create a list of rooms | ||
|
||
room_number = 1 | ||
20.times do # 20 rooms from requirements | ||
#20 times... do... | ||
@rooms << room_number | ||
room_number = room_number + 1 | ||
end | ||
end | ||
# access the list of reservations for a specified room and a given date range | ||
def list_reservations_for_room(room, start_date, end_date) | ||
list = [] # returns an array of reservations that falls within the date range | ||
@reservations.each do |reservation| | ||
if room == reservation.room_number | ||
if reservation.date_range.overlap?(start_date, end_date) | ||
list << reservation | ||
end | ||
end | ||
end | ||
return list | ||
end | ||
|
||
def reserve_room(start_date, end_date) | ||
# start_date and end_date should be instances of class Date | ||
# looks through room numbers and get reservations for the date in question until we find one with no reservations | ||
available = find_available_rooms(start_date, end_date) | ||
|
||
# check for available rooms | ||
if available.length > 0 | ||
newly_created_reservation = Reservation.new(start_date, end_date, available[0]) | ||
reservations << newly_created_reservation | ||
return newly_created_reservation | ||
else | ||
raise ArgumentError, "No available rooms." | ||
end | ||
end | ||
# access the list of reservations for a specific date, | ||
# so that it can track reservations by date | ||
def show_reservations_for_date(date) | ||
# go through reservations and add the ones whose range include the given date | ||
list = [] | ||
@reservations.each do |reservation| | ||
if reservation.date_range.include?(date) | ||
list << reservation | ||
end | ||
end | ||
return list | ||
end | ||
|
||
# Wave 2 | ||
def find_available_rooms(start_date, end_date) | ||
# start_date and end_date should be instances of class Date | ||
available_rooms = [] | ||
# iterate through the rooms to find available room | ||
@rooms.each do |room| | ||
reservations = list_reservations_for_room(room, 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. Interesting design choice to use |
||
|
||
if(reservations.length() == 0) # rooms that are empty | ||
available_rooms << room | ||
end | ||
end | ||
return available_rooms | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Hotel | ||
class Reservation | ||
attr_reader :date_range, :start_date, :end_date, :room_number | ||
|
||
# initizlize | ||
def initialize(start_date, end_date, room_number) | ||
@date_range = DateRange.new(start_date, end_date) | ||
@room_number = room_number | ||
@start_date = start_date | ||
@end_date = end_date | ||
|
||
end | ||
|
||
# get the total cost for a given reservation | ||
def cost | ||
return @date_range.nights * 200 | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nice use of a boolean expression to return
true
orfalse
. You don't even need a conditional :)