Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7465da1
set up
stephaniejmars Mar 2, 2020
40e66fb
added room initialize & tests
stephaniejmars Mar 2, 2020
f57b318
method create_rooms added with test
stephaniejmars Mar 3, 2020
1388482
updated to take out cost
stephaniejmars Mar 4, 2020
305982b
initalize begun, not completed
stephaniejmars Mar 4, 2020
4831bfd
tests started - not complete.
stephaniejmars Mar 4, 2020
214e1d5
updated to take out cost
stephaniejmars Mar 4, 2020
380c6c1
initalize - not complete
stephaniejmars Mar 4, 2020
60f858d
initalize - not completed
stephaniejmars Mar 4, 2020
237e3e1
moved building rooms to Manager. Added recloc and corrected total_cos…
stephaniejmars Mar 4, 2020
e70bbe9
setting up to check availablity in Reservation. added rm res array to…
stephaniejmars Mar 5, 2020
661e774
pseudo code to change layout, booking res will be in Room class, alon…
stephaniejmars Mar 5, 2020
79e36e2
building code in room and manager to complete book_room, and is_avail…
stephaniejmars Mar 5, 2020
65526d1
added date_range method
stephaniejmars Mar 7, 2020
27b3415
updated book_res in Manager class to match with new range method in R…
stephaniejmars Mar 7, 2020
fd154c1
added overlap method. And it works! lol
stephaniejmars Mar 8, 2020
82fe8cd
pseudo set up for manager methods, res_by_room, res_by_date, total_cost
stephaniejmars Mar 8, 2020
54b5825
breaking down initialize and create_rooms, found error in intialize..…
stephaniejmars Mar 8, 2020
6128351
initalize updated to take different parameters, show all rooms workin…
stephaniejmars Mar 8, 2020
c848cca
added return in book_room, correctly book rooms test working now.
stephaniejmars Mar 8, 2020
59d2694
moved simplecov up to work correctly
stephaniejmars Mar 8, 2020
a28ab4e
book res updated and test running.
stephaniejmars Mar 8, 2020
bce7423
added in rooms has_res_by_date method, and res_by_room method in Mana…
stephaniejmars Mar 9, 2020
d292dd4
res_by_date and tests completed.
stephaniejmars Mar 9, 2020
4f1dd3a
fixed find_total cost and tests, added new parameter in book_room.
stephaniejmars Mar 9, 2020
2214448
deleted overlap method in room, fixed rooms_available_by_date in mana…
stephaniejmars Mar 9, 2020
6ee69f6
fixed indents and comments.
stephaniejmars Mar 9, 2020
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
93 changes: 93 additions & 0 deletions lib/manager.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
require 'time'
require 'date'
require_relative 'room'
require_relative 'reservation'


module Hotel
class Manager
attr_reader :num, :all_rooms, :rm_reservations, :recloc

Choose a reason for hiding this comment

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

This should only define readers for instance variable of the Hotel class. The only of these 4 that is an instance variable of Hotel is all_rooms.

Suggested change
attr_reader :num, :all_rooms, :rm_reservations, :recloc
attr_reader :all_rooms

Choose a reason for hiding this comment

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

I imagine you might understand that and just forgot to update this line.

attr_writer
attr_accessor
Comment on lines +10 to +11

Choose a reason for hiding this comment

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

Just so you know, these lines aren't needed when you don't have any attributes you want to list for them.


def initialize(num: 20)

Choose a reason for hiding this comment

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

This is a great way to set this up! A great example of where input params to a constructor can be totally different than the instance variable(s)!

if num == nil || num == 20
@all_rooms = Manager.create_rooms
else
@all_rooms = Manager.create_rooms(num: num)
end
end

def self.create_rooms(num: 20)

Choose a reason for hiding this comment

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

Cool that you made this its own method!

@all_rooms = []
i = 1
num.times do
@all_rooms << Room.new(rm_num: i)
i += 1
end
return @all_rooms
end

def show_all_rooms
list_rooms = []
@all_rooms.each do |room|
list_rooms << room.rm_num
end
return list_rooms
end

def book_res(start_date, end_date)
@all_rooms.each do |room|
if room.is_available_range(start_date, end_date) == true
return room.book_room(start_date, end_date)
end
end
raise ArgumentError.new("No rooms available")
end

def res_by_room(rm_num, start_date, end_date)
res_array = []
@found_room = @all_rooms.find {|room| room.rm_num}

Choose a reason for hiding this comment

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

This could/should be a local variable rather than an instance variable since it is only used within this one method.
That would be changed by just removing the @

Suggested change
@found_room = @all_rooms.find {|room| room.rm_num}
found_room = @all_rooms.find {|room| room.rm_num}

(start_date..end_date).each do |date|
res = @found_room.has_res_by_date(date)
if res != false && res_array.include?(res) == false
res_array << res
end
end
return res_array
end

def res_by_date(date)
res_array = []
@all_rooms.each do |room|
res = room.has_res_by_date(date)
res_array << res
end
return res_array
end

def rooms_available_by_date(start_date, end_date)
room_array = []
@all_rooms.each do |room|
if room.is_available_range(start_date, end_date) == true
room_array << room
end
end
return room_array
end

def find_total_cost(rec_loc)
res = ""
@all_rooms.each do |room|
if room.rm_reservations.find{|res| res.recloc[:recloc] == rec_loc}.class == Hotel::Reservation

Choose a reason for hiding this comment

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

This is just slightly too indented.
I use this handy VSCode plugin called "indent-rainbow" to make that really easy to notice.

res = room.rm_reservations.find{|res| res.recloc[:recloc] == rec_loc}
end
end
return res.total_cost
end


end
end


32 changes: 32 additions & 0 deletions lib/reservation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'time'
require 'date'
require 'securerandom'
require_relative 'manager'
require_relative 'room'

module Hotel
class Reservation
attr_reader :start_date, :end_date, :rm_num, :cost_per_day, :total_cost, :recloc

Choose a reason for hiding this comment

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

These all correspond to instance variables. Great!


def initialize(start_date:,
end_date:,
rm_num: nil,
cost_per_day: 200,
total_cost: nil,
recloc: nil)

Choose a reason for hiding this comment

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

I'm having trouble understanding what this variable represents. It's best to name variables in such a way that their purpose is clear to anyone who might read the code.


@start_date = Date.parse "#{start_date}"
@end_date = Date.parse "#{end_date}"
@cost_per_day = cost_per_day
@rm_num = rm_num
res_length = (Date.parse("#{end_date}") - Date.parse("#{start_date}")).to_i
@total_cost = cost_per_day * res_length
if recloc == nil
@recloc = SecureRandom.alphanumeric(6)
else
@recloc = recloc
end
end
end
end

69 changes: 69 additions & 0 deletions lib/room.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
require 'time'
require 'date'
require_relative 'manager'
require_relative 'reservation'

module Hotel
class Room
attr_reader :rm_num, :rm_reservations
attr_writer
attr_accessor

def initialize(rm_num:)
@rm_num = rm_num
@rm_reservations = []

if rm_num.nil? || rm_num <= 0
raise ArgumentError, 'Room number cannot be blank or less than one.'
end
end


def is_available(date)
if @rm_reservations == nil #if no res then room is avail
return true
else
@rm_reservations.each do |res|
if date < res.start_date || date >= res.end_date
#loops again
else
return false
end
end
end
return true
end

def is_available_range(start_date, end_date)
(start_date..(end_date-1)).each do |date|
if is_available(date) == false
return false
end
end
return true
end


def book_room(start_date, end_date, recloc = nil)
@reservation = Reservation.new(start_date: start_date,
end_date: end_date,
rm_num: @rm_num,
recloc: recloc)
@rm_reservations << @reservation
return @reservation
end

def has_res_by_date(date)
if @rm_reservations == []
return false
else
@rm_reservations.each do |res|
if date >= res.start_date && date <= res.end_date
return res
end
end
end
return false
end
end
end
5 changes: 5 additions & 0 deletions test/coverage/.last_run.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"result": {
"covered_percent": 100.0
}
}
7 changes: 7 additions & 0 deletions test/coverage/.resultset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"Minitest": {
"coverage": {
},
"timestamp": 1583646250
}
}
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/coverage/assets/0.12.2/application.css

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions test/coverage/assets/0.12.2/application.js

Large diffs are not rendered by default.

Binary file added test/coverage/assets/0.12.2/colorbox/border.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/coverage/assets/0.12.2/colorbox/controls.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/coverage/assets/0.12.2/colorbox/loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/coverage/assets/0.12.2/favicon_green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/coverage/assets/0.12.2/favicon_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/coverage/assets/0.12.2/favicon_yellow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/coverage/assets/0.12.2/loading.gif
Binary file added test/coverage/assets/0.12.2/magnify.png
93 changes: 93 additions & 0 deletions test/coverage/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>Code coverage for Test</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src='./assets/0.12.2/application.js' type='text/javascript'></script>
<link href='./assets/0.12.2/application.css' media='screen, projection, print' rel='stylesheet' type='text/css' />
<link rel="shortcut icon" type="image/png" href="./assets/0.12.2/favicon_green.png" />
<link rel="icon" type="image/png" href="./assets/0.12.2/favicon.png" />
</head>

<body>
<div id="loading">
<img src="./assets/0.12.2/loading.gif" alt="loading"/>
</div>
<div id="wrapper" class="hide">
<div class="timestamp">Generated <abbr class="timeago" title="2020-03-07T21:44:10-08:00">2020-03-07T21:44:10-08:00</abbr></div>
<ul class="group_tabs"></ul>

<div id="content">
<div class="file_list_container" id="AllFiles">
<h2>
<span class="group_name">All Files</span>
(<span class="covered_percent">
<span class="green">
100.0%
</span>

</span>
covered at
<span class="covered_strength">
<span class="red">
0.0
</span>
</span> hits/line
)
</h2>

<a name="AllFiles"></a>

<div>
<b>0</b> files in total.
</div>

<div class="t-line-summary">
<b>0</b> relevant lines,
<span class="green"><b>0</b> lines covered</span> and
<span class="red"><b>0</b> lines missed. </span>
(<span class="green">
100.0%
</span>
)
</div>



<div class="file_list--responsive">
<table class="file_list">
<thead>
<tr>
<th>File</th>
<th class="cell--number">% covered</th>
<th class="cell--number">Lines</th>
<th class="cell--number">Relevant Lines</th>
<th class="cell--number">Lines covered</th>
<th class="cell--number">Lines missed</th>
<th class="cell--number">Avg. Hits / Line</th>

</tr>
</thead>
<tbody>

</tbody>
</table>
</div>
</div>



</div>

<div id="footer">
Generated by <a href="https://github.com/colszowka/simplecov">simplecov</a> v0.18.5
and simplecov-html v0.12.2<br/>
using Minitest
</div>

<div class="source_files">

</div>
</div>
</body>
</html>
Loading