Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/test/tmp/
/test/version_tmp/
/tmp/
/junk/

# Used by dotenv library to load environment variables.
# .env
Expand Down
2 changes: 1 addition & 1 deletion Guardfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
guard :minitest, bundler: false, rubygems: false do
guard :minitest, bundler: false, autorun: false, rubygems: false do
# with Minitest::Spec
watch(%r{^spec/(.*)_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
Expand Down
11 changes: 11 additions & 0 deletions data/all_hotel_rooms.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
room_number,cost,status,reserved_dates
1,200,available,[]
2,200,available,[]
3,200,available,[]
4,200,available,[]
5,200,available,[]
6,200,available,[]
7,200,available,[]
8,200,available,[]
9,200,available,[]
10,200,available,[]
1 change: 1 addition & 0 deletions data/reservations.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
room_number,cost,status,check_in,check_out
68 changes: 68 additions & 0 deletions design-activity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Activity: Evaluating Responsibility

## Prompts
Once you have read through the above code, add a file to your Hotel project called design-activity.md. This file will be submitted with the rest of this exercise. In that file, please respond to the following prompts:

### What classes does each implementation include? Are the lists the same?
Write down a sentence to describe each class.
Each implementation has: CartEntry, ShoppingCart, and Order classes.
CartEntry = the price and quantity are stored as instance variables upon initialization. Implemetation B's version also has the instance method price which returns the product of the unit price and quantity.
ShoppingCart = an empty array (instance variable entries) is created upon initialization. For implementation B, it also has the instance method 'price', which sums the price of each entry in the array @entries.
Order = the Order creates a new instance of ShoppingCart upon initialization. Both implementations have instance method 'total_price', however in implenentation A, the sum is calculated by using the instance variable entries in the ShoppingCart class with the instance variable cart in the Order class. In implementation B, the method stays within the class, using Order's instance varialbe cart only.




### How do the classes relate to each other? It might be helpful to draw a diagram on a whiteboard or piece of paper.
Implementation A - the classes are interwoven, attr_accessor is used to interweave the classes together. The Order class is reliant on the CartEntry and ShoppingCart classes for calculating total price.

Implementation B - the classes are more independent from each other, the Order class is reliant only on information from the ShoppingCart method and only because a new ShoppingCart is initialized with its creation.



### What data does each class store? How (if at all) does this differ between the two implementations? What methods does each class have? How (if at all) does this differ between the two implementations?
In implementation B, all classes not only store information but are responsible for calculations for each instance of itself. In implementation A, however, Order is responsible for everyone.


### Consider the Order#total_price method. In each implementation:
Is logic to compute the price delegated to "lower level" classes like ShoppingCart and CartEntry, or is it retained in Order?
Does total_price directly manipulate the instance variables of other classes?
In implementation B, it is delegated to lower level classes, in A it directly manipulates the other classes' instance vars.


### If we decide items are cheaper if bought in bulk, how would this change the code? Which implementation is easier to modify?
Which implementation better adheres to the single responsibility principle?
Implementation B isn't as tightly woven as A. Since all classes are responsible for their own thing and have their own methods that perform calculations, it is much easier to create a class or other edit. As opposed to A which must be fully changed from top-bottom in order to add that functionality.


### Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled?
Implementation B


Once you've responded to the prompts, git add design-activity.md and git commit!

****

Now that we've got you thinking about design, spend some time to revisit the code you wrote for the Hotel project. For each class in your program, ask yourself the following questions:

What is this class's responsibility?
You should be able to describe it in a single sentence.
Is this class responsible for exactly one thing?
Does this class take on any responsibility that should be delegated to "lower level" classes?
Is there code in other classes that directly manipulates this class's instance variables?
You might recall writing a file called refactor.txt. Take a look at the refactor plans that you wrote, and consider the following:

How easy is it to follow your own instructions?
Do these refactors improve the clarity of your code?
Do you still agree with your previous assesment, or could your refactor be further improved?
****

### Based on the answers to each set of the above questions, identify one place in your Hotel project where a class takes on multiple roles, or directly modifies the attributes of another class. Describe in design-activity.md what changes you would need to make to improve this design, and how the resulting design would be an improvement.
Changed a bunch of stuff, remove CSV stuff since it didn't work out, change some methods and clearly separate module from class. Moved module methods to Concierge class, but I think the program as a whole needs a rehaul.


If you need inspiration, remember that the reference implementation exists.

Then make the changes! Don't forget to take advantage of all the tests you wrote - if they're well structured, they should quickly inform you when your refactoring breaks something.

Once you're satisfied, git commit your changes and then push them to GitHub. This will automatically update your pull request.
62 changes: 62 additions & 0 deletions junk/admin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require 'awesome_print'
require 'date'
#concierge can VIEW reservations
#concierge can RESERVE reservation
#concierge can ACCESS receipt for completed stay
#concierge can ACCESS hotel room list = yes
#can datevar.strftime("%b %d, %Y")

module Lodging #namespace/container
#similar to the main.rb of other projects
class Concierge #small hotel
attr_accessor :room_hash

def initialize(room_count)
Lodging.create_rooms(room_count) #creating rooms upon initialization
end

def all_rooms
room_hash = []
Room.show_list.each do |room|
room_info = {}
# room = "Room #{room.room_number} costs $#{room.cost} a night and is #{room.status}."
room_info[:room_number] = room.room_number
room_info[:price] = room.cost
room_info[:status] = room.status

room_hash << room_info
end
return room_hash
end


def new_reservation(check_in, check_out, block = 1)
raise ArgumentError if Date.parse(check_out) < Date.parse(check_in)
#
# status = block > 1 ? :hold : :unavailable #hold if block, unavailable if single reservation

# block.times do
book_this = Lodging.reservation(all_rooms, status)
book_this[:check_in] = Date.parse(check_in)
book_this[:check_out] = Date.parse(check_out)
ap book_this
# end
#
# @room_hash.find do |room|
# room[:room_number] == book_this[:room_number]
# # book_this[:status] = :unavailable
# end

# booked[:status] = :unavailable

end

def search_reservation(date)


end

end


end
45 changes: 45 additions & 0 deletions junk/admin_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require_relative 'spec_helper'

describe 'Concierge class' do
before(:each) do
Lodging::Room.class_variable_set(:@@room_list, [])
end

let(:concierge) {
Lodging::Concierge.new(10)
}

describe 'all_rooms method' do
it 'shows all rooms in hotel' do
# Lodging.create_rooms(10)

room_list = concierge.all_rooms

expect(room_list.any? Hash).must_equal true
expect(room_list.length).must_equal 10
end

end

describe 'new reservation method' do
let(:new_booking) {
concierge.new_reservation('201876', '201878')
}

it 'errors if invalid date is entered' do
expect{concierge.new_reservation('201876', '201778')}.must_raise ArgumentError
end

# it 'creates a check_in and check_out dates for room' do
# ap concierge
#
# end

end

describe 'search reservation' do
it 'can find a reservation based on date' do

end
end
end
42 changes: 42 additions & 0 deletions junk/reservation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require 'awesome_print'
require 'date'
require 'pry'
#reservation CREATES reservations
#reservation TOTALS costs of stay

module Lodging

def self.room_status(input) #check room_status
avail = input.find do |room|
room[:status] == :available #returns first instance it finds of available room
end

return avail
end

# module Reservation

def self.reservation(input) #switches status from avail to unavail
room = Lodging.room_status(input)

room[:status] = status

Lodging::Room.status_change(room[:room_number], status)

room[:start_date] = nil
room[:end_date] = nil
# check status, if available
# takes date range
# switches status to unavailable
end
# end

def self.receipt #calculates total cost of stay
#counts days in range
#multiply count by
#can date var -= 1 to get day before

end


end
60 changes: 60 additions & 0 deletions junk/reservation_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
require_relative 'spec_helper'

describe 'Lodging Reservation methods' do
before(:each) do
Lodging::Room.class_variable_set(:@@room_list, [])
end

let(:concierge){
Lodging::Concierge.new(15)
}

describe 'check status' do
before do
Lodging.create_rooms(5)
end

describe 'room status' do
it 'errors if no available rooms' do
room = [{room_number: 2, status: :unavailable, cost: 200}]

ap room

expect(Lodging.room_status(room)).must_raise ArgumentError

end

end

it 'returns one available room if no error' do
avail = Lodging.room_status(concierge.all_rooms)
# ap avail

expect(avail).must_be_instance_of Hash
expect(avail[:status]).must_equal :available

end
end

# describe 'reservation' do
# it 'switches room status to unavailable' do
#
# end
#
# it 'switches status of room instance to unavailable' do
#
# end
#
# end

# describe 'reciept' do
# it 'calculates room total based on room cost per night' do
#
# end
#
# it 'does not calculate last date of reservation in total' do
#
# end
# end

end
Empty file removed lib/.keep
Empty file.
Loading