-
Notifications
You must be signed in to change notification settings - Fork 40
Space - Stephanie #31
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?
Changes from all commits
7465da1
40e66fb
f57b318
1388482
305982b
4831bfd
214e1d5
380c6c1
60f858d
237e3e1
e70bbe9
661e774
79e36e2
65526d1
27b3415
fd154c1
82fe8cd
54b5825
6128351
c848cca
59d2694
a28ab4e
bce7423
d292dd4
4f1dd3a
2214448
6ee69f6
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 | ||||
|---|---|---|---|---|---|---|
| @@ -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 | ||||||
| attr_writer | ||||||
| attr_accessor | ||||||
|
Comment on lines
+10
to
+11
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. 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) | ||||||
|
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 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) | ||||||
|
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. 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} | ||||||
|
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 could/should be a local variable rather than an instance variable since it is only used within this one method.
Suggested change
|
||||||
| (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 | ||||||
|
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 is just slightly too indented. |
||||||
| res = room.rm_reservations.find{|res| res.recloc[:recloc] == rec_loc} | ||||||
| end | ||||||
| end | ||||||
| return res.total_cost | ||||||
| end | ||||||
|
|
||||||
|
|
||||||
| end | ||||||
| end | ||||||
|
|
||||||
|
|
||||||
| 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 | ||
|
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. 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) | ||
|
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. 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 | ||
|
|
||
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "result": { | ||
| "covered_percent": 100.0 | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "Minitest": { | ||
| "coverage": { | ||
| }, | ||
| "timestamp": 1583646250 | ||
| } | ||
| } |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| 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> |
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.
This should only define readers for instance variable of the
Hotelclass. The only of these 4 that is an instance variable ofHotelisall_rooms.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.
I imagine you might understand that and just forgot to update this line.