forked from AdaGold/hotel
-
Notifications
You must be signed in to change notification settings - Fork 48
Ports - Shamira #39
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
Open
MiraMarshall
wants to merge
8
commits into
Ada-C11:master
Choose a base branch
from
MiraMarshall: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
Ports - Shamira #39
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
95b82f2
testing Guard
MiraMarshall e1cdbdc
testing guard
MiraMarshall 327dfc9
Added Classes and some initialize tests for reservation.rb and room.rb
MiraMarshall e7b485b
Finished reservation class and tests. Can access a list of rooms and …
MiraMarshall df088bd
Manager class and tests.
MiraMarshall 8564c97
deleted class for re-design
MiraMarshall 084df93
fixed reservation_spec tests
MiraMarshall 8549bca
changed manager.rb to match variable name changes in reservation.rb
MiraMarshall 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 hidden or 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,22 @@ | ||
|
|
||
|
|
||
| require_relative "reservation" | ||
| require_relative "room" | ||
|
|
||
| class Manager | ||
| attr_reader :rooms | ||
|
|
||
| def initialize | ||
| @rooms = rooms | ||
| end | ||
|
|
||
| def make_rooms | ||
| @rooms = (1..20).to_a.map! do |room| | ||
| Room.new(id: room) | ||
| end | ||
| end | ||
|
|
||
| def all_reservations | ||
| @reservations << book_reservation(vacant_room, check_in, check_out) | ||
| end | ||
| end | ||
This file contains hidden or 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,35 @@ | ||
| class Reservation | ||
| attr_reader :room_num, :check_in, :check_out, :rate, :rooms | ||
|
|
||
| def initialize(room_num:, check_in:, check_out:, rooms:) | ||
| @room_num = available_room(rooms) | ||
| @rate = 200 | ||
| @check_in = Date.parse(check_in) | ||
|
|
||
| @check_out = Date.parse(check_out) | ||
| if !@check_out.nil? && @check_out < @check_in | ||
| raise ArgumentError.new("Check-out date before check-in date") | ||
| end | ||
| @reservations = [] | ||
|
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. Why would a |
||
| end | ||
|
|
||
| def available_room(rooms) | ||
| vacant_room = rooms.find_index do |room| | ||
| next if !room.dates.empty? | ||
| else | ||
| return room #compare dates or choose empty? room | ||
| end | ||
| # # take the first available room and assign it. | ||
| # # add to the bookings array. | ||
| return vacant_room | ||
| end | ||
|
|
||
| def book_reservation(vacant_room, check_in, check_out) | ||
| end | ||
|
|
||
| def total_cost | ||
|
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. 👍 |
||
| duration = (check_out - check_in).to_i | ||
| total_cost = duration * @rate | ||
| return total_cost | ||
| end | ||
| end | ||
This file contains hidden or 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,9 @@ | ||
|
|
||
| class Room | ||
| attr_reader :id, :reservation, :rooms, :dates | ||
|
|
||
| def initialize(id:) | ||
| @id = id | ||
| @dates = [] | ||
| end | ||
| end |
This file contains hidden or 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,32 @@ | ||
| require_relative "spec_helper" | ||
| describe "Manager Class" do | ||
| before do | ||
| room_num = 5 | ||
| check_in = Date.parse("2019-05-14") | ||
| check_out = Date.parse("2019-05-18") | ||
| rooms = [] | ||
| rooms << Room.new(id: 1) | ||
| rooms << Room.new(id: 2) | ||
| rooms << Room.new(id: 3) | ||
|
|
||
| @reservation1_data = { | ||
| room_num: 5, | ||
| check_in: check_in.to_s, | ||
| check_out: check_out.to_s, | ||
| rooms: rooms, | ||
|
|
||
| } | ||
| @reservation2_data = { | ||
| room_num: 7, | ||
| check_in: Date.parse("2019-06-02").to_s, | ||
| check_out: Date.parse("2019-06-04").to_s, | ||
| rooms: rooms, | ||
| } | ||
| @reservation1 = Reservation.new(@reservation1_data) | ||
| @reservation2 = Reservation.new(@reservation2_data) | ||
| @manager = Manager.new | ||
| end | ||
| it "is an instance of Manager" do | ||
| expect(@manager).must_be_kind_of Manager | ||
| end | ||
| end |
This file contains hidden or 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,43 @@ | ||
| require_relative "spec_helper" | ||
| describe "Reservation Class" do | ||
| describe "initialize" do | ||
| before do | ||
| room_num = 5 | ||
| check_in = Date.parse("2019-05-14") | ||
| check_out = Date.parse("2019-05-18") | ||
| rate = 200 | ||
| rooms = [] | ||
| rooms << Room.new(id: 1) | ||
| rooms << Room.new(id: 2) | ||
| rooms << Room.new(id: 3) | ||
|
|
||
| @reservation_data = { | ||
| room_num: 5, | ||
| check_in: check_in.to_s, | ||
| check_out: check_out.to_s, | ||
| rooms: rooms, | ||
|
|
||
| } | ||
| @reservation = Reservation.new(@reservation_data) | ||
| end | ||
|
|
||
| it "has a check-out date that is after the check-in date." do | ||
| expect(@reservation.check_out > @reservation.check_in).must_equal true | ||
| end | ||
|
|
||
| it "throws ArgumentError when check-out date is before the check-in date." do | ||
| expect do | ||
| Reservation.new(room_num: 7, check_in: "2019-05-14", check_out: "2019-05-13", rate: 200) | ||
| end.must_raise ArgumentError | ||
| end | ||
|
|
||
| it "is an instance of Reservation" do | ||
| expect(@reservation).must_be_kind_of Reservation | ||
| end | ||
|
|
||
| it "calculates the total cost of the stay" do | ||
| expect(@reservation.total_cost).must_equal 800 | ||
| puts "This reservation will cost $#{@reservation.total_cost}." | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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,14 @@ | ||
| require_relative "spec_helper" | ||
|
|
||
| describe "Room Class" do | ||
| describe "Room initializer" do | ||
| before do | ||
| @room = Room.new( | ||
| id: 1, | ||
| ) | ||
| end | ||
| it "is an instance of Room" do | ||
| expect(@room).must_be_kind_of Room | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,8 +1,12 @@ | ||
| # Add simplecov | ||
| require 'minitest' | ||
| require 'minitest/autorun' | ||
| require 'minitest/reporters' | ||
| require "simplecov" | ||
| SimpleCov.start | ||
| require "date" | ||
| require "minitest" | ||
| require "minitest/autorun" | ||
| require "minitest/reporters" | ||
|
|
||
| Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new | ||
|
|
||
| # Require_relative your lib files here! | ||
| require_relative "../lib/manager" | ||
| require_relative "../lib/reservation" | ||
| require_relative "../lib/room" |
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.
This class seems pretty small for a "Manager" class which coordinates the reservations etc. I would also expect that it would have a list of reservations.