From c8510d8e8df6226797762c1bdc0d80d5bd0581c2 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Tue, 4 Sep 2018 13:41:39 -0700 Subject: [PATCH 01/18] barebones created --- spec/block_spec.rb | 0 spec/hotel_spec.rb | 0 spec/reservation_spec.rb | 0 spec/room_spec.rb | 0 spec/spec_helper.rb | 4 ++++ 5 files changed, 4 insertions(+) create mode 100644 spec/block_spec.rb create mode 100644 spec/hotel_spec.rb create mode 100644 spec/reservation_spec.rb create mode 100644 spec/room_spec.rb diff --git a/spec/block_spec.rb b/spec/block_spec.rb new file mode 100644 index 000000000..e69de29bb diff --git a/spec/hotel_spec.rb b/spec/hotel_spec.rb new file mode 100644 index 000000000..e69de29bb diff --git a/spec/reservation_spec.rb b/spec/reservation_spec.rb new file mode 100644 index 000000000..e69de29bb diff --git a/spec/room_spec.rb b/spec/room_spec.rb new file mode 100644 index 000000000..e69de29bb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4d1e3fdc8..c2d7d0b04 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,3 +6,7 @@ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new # Require_relative your lib files here! +require_relative 'lib/block' +require_relative 'lib/hotel' +require_relative 'lib/reservation' +require_relative 'lib/room' From 1985514edb639d18c5516a026c947296a321babc Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Tue, 4 Sep 2018 13:45:08 -0700 Subject: [PATCH 02/18] barebones done --- Guardfile | 2 +- lib/.keep | 0 lib/block.rb | 7 +++++++ lib/hotel.rb | 13 +++++++++++++ lib/reservation.rb | 5 +++++ lib/room.rb | 9 +++++++++ spec/block_spec.rb | 1 + spec/hotel_spec.rb | 1 + spec/reservation_spec.rb | 1 + spec/room_spec.rb | 1 + spec/spec_helper.rb | 5 ++++- 11 files changed, 43 insertions(+), 2 deletions(-) delete mode 100644 lib/.keep create mode 100644 lib/block.rb create mode 100644 lib/hotel.rb create mode 100644 lib/reservation.rb create mode 100644 lib/room.rb diff --git a/Guardfile b/Guardfile index 6760f9177..fa59fc3ef 100644 --- a/Guardfile +++ b/Guardfile @@ -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" } diff --git a/lib/.keep b/lib/.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/lib/block.rb b/lib/block.rb new file mode 100644 index 000000000..809ef401a --- /dev/null +++ b/lib/block.rb @@ -0,0 +1,7 @@ +module Lodging #name space to contain all info, including non-inherited classes + class Block < Room #a special 'room' that is really a lot of unreserved rooms for 'vips' + @rooms = rooms + + end + +end diff --git a/lib/hotel.rb b/lib/hotel.rb new file mode 100644 index 000000000..e89eace3c --- /dev/null +++ b/lib/hotel.rb @@ -0,0 +1,13 @@ +module Lodging #name space to contain all info, including non-inherited classes +class Hotel + attr_reader :hotel_name + + def initialize(hotel_name, rooms) + @hotel_name = hotel_name + @room_count = rooms + end + + +end + +end diff --git a/lib/reservation.rb b/lib/reservation.rb new file mode 100644 index 000000000..55996c453 --- /dev/null +++ b/lib/reservation.rb @@ -0,0 +1,5 @@ +module Lodging #name space to contain all info, including non-inherited classes + class Reservation #reservations apart from room + end + +end diff --git a/lib/room.rb b/lib/room.rb new file mode 100644 index 000000000..c4bdac81a --- /dev/null +++ b/lib/room.rb @@ -0,0 +1,9 @@ +module Lodging #name space to contain all info, including non-inherited classes + class Room < Hotel + def initialize(room_number, status) + @room_number = room_number + @status = status #available, unavailable, hold? + end + end + +end diff --git a/spec/block_spec.rb b/spec/block_spec.rb index e69de29bb..ae9c220ea 100644 --- a/spec/block_spec.rb +++ b/spec/block_spec.rb @@ -0,0 +1 @@ +require_relative 'spec_helper' diff --git a/spec/hotel_spec.rb b/spec/hotel_spec.rb index e69de29bb..ae9c220ea 100644 --- a/spec/hotel_spec.rb +++ b/spec/hotel_spec.rb @@ -0,0 +1 @@ +require_relative 'spec_helper' diff --git a/spec/reservation_spec.rb b/spec/reservation_spec.rb index e69de29bb..ae9c220ea 100644 --- a/spec/reservation_spec.rb +++ b/spec/reservation_spec.rb @@ -0,0 +1 @@ +require_relative 'spec_helper' diff --git a/spec/room_spec.rb b/spec/room_spec.rb index e69de29bb..ae9c220ea 100644 --- a/spec/room_spec.rb +++ b/spec/room_spec.rb @@ -0,0 +1 @@ +require_relative 'spec_helper' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c2d7d0b04..1ffd49207 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,10 @@ +#### +require 'simplecov' +SimpleCov.start +#### require 'minitest' require 'minitest/autorun' require 'minitest/reporters' -# Add simplecov Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new From a88dc1396f93a6b8f5581ed2fd0061b1291fefa7 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Tue, 4 Sep 2018 15:13:04 -0700 Subject: [PATCH 03/18] hotel class and room class can initialize, can list rooms --- lib/block.rb | 14 +++++++------- lib/hotel.rb | 36 +++++++++++++++++++++++++++++------- lib/reservation.rb | 10 +++++----- lib/room.rb | 15 +++++++++++---- spec/hotel_spec.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ spec/room_spec.rb | 11 +++++++++++ spec/spec_helper.rb | 8 ++++---- 7 files changed, 109 insertions(+), 27 deletions(-) diff --git a/lib/block.rb b/lib/block.rb index 809ef401a..e5de6e6d7 100644 --- a/lib/block.rb +++ b/lib/block.rb @@ -1,7 +1,7 @@ -module Lodging #name space to contain all info, including non-inherited classes - class Block < Room #a special 'room' that is really a lot of unreserved rooms for 'vips' - @rooms = rooms - - end - -end +# module Lodging #name space to contain all info, including non-inherited classes +# class Block < Room #a special 'room' that is really a lot of unreserved rooms for 'vips' +# @rooms = rooms +# +# end +# +# end diff --git a/lib/hotel.rb b/lib/hotel.rb index e89eace3c..f36426126 100644 --- a/lib/hotel.rb +++ b/lib/hotel.rb @@ -1,13 +1,35 @@ +# require 'awesome_print' +# require_relative 'block' +# require_relative 'room' +# require_relative 'reservation' + +#can access list of all rooms in hotel? = yes +#can create new rooms automagically? = yes + module Lodging #name space to contain all info, including non-inherited classes -class Hotel - attr_reader :hotel_name + class Hotel + attr_reader :name, :room_count, :rooms - def initialize(hotel_name, rooms) - @hotel_name = hotel_name - @room_count = rooms - end + def initialize(hotel_name, room_count) + raise ArgumentError if room_count == nil || room_count <= 0 + @name = hotel_name + @room_count = room_count + @rooms = create_rooms(room_count) + end -end + def create_rooms(room_number) #method to create instances of room based on room_count + rooms = [] + room_number = 1 + @room_count.times do + new_room = Room.new(room_number) + room_number += 1 + rooms << new_room + end + return rooms + end + + + end end diff --git a/lib/reservation.rb b/lib/reservation.rb index 55996c453..7d4420321 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,5 +1,5 @@ -module Lodging #name space to contain all info, including non-inherited classes - class Reservation #reservations apart from room - end - -end +# module Lodging #name space to contain all info, including non-inherited classes +# class Reservation #reservations apart from room +# end +# +# end diff --git a/lib/room.rb b/lib/room.rb index c4bdac81a..32f481097 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,9 +1,16 @@ +# require_relative 'room' +# require_relative 'hotel' +# require_relative 'block' +# require_relative 'reservation' + module Lodging #name space to contain all info, including non-inherited classes - class Room < Hotel - def initialize(room_number, status) + class Room + attr_reader :room_number, :status, :cost + + def initialize(room_number, cost = 200) #default price is 200/night @room_number = room_number - @status = status #available, unavailable, hold? + @status = :AVAILABLE #available, unavailable, hold? + @cost = cost end end - end diff --git a/spec/hotel_spec.rb b/spec/hotel_spec.rb index ae9c220ea..71ca64013 100644 --- a/spec/hotel_spec.rb +++ b/spec/hotel_spec.rb @@ -1 +1,43 @@ require_relative 'spec_helper' + +describe 'Hotel Wave 1' do + describe 'initalize' do + it 'creates a hotel with attr name' do + my_hotel = Lodging::Hotel.new("My Hotel", 20) + + expect(my_hotel).must_respond_to :name + expect(my_hotel.name).must_equal "My Hotel" + + expect(my_hotel).must_respond_to :room_count + expect(my_hotel.room_count).must_equal 20 + + expect(my_hotel).must_respond_to :rooms + end + # + it 'errors if arg in rooms param is not an integer' do + expect{ + Lodging::Hotel.new("My Hotel","twenty") + }.must_raise ArgumentError + end + + it 'errors if arg for rooms param is 0' do + expect{ + Lodging::Hotel.new("My Hotel", 0) + }.must_raise ArgumentError + end + # + # it 'errors if arg in hotel_name param is not a string' do + # expect{ + # Lodging::Hotel.new(hotel49, 20) + # }.must_raise ArgumentError + # end + + it 'creates new Room class instances based on room_count' do + my_hotel = Lodging::Hotel.new("My Hotel", 20) + + expect(my_hotel.rooms).must_be_kind_of Array + expect(my_hotel.rooms.all? Lodging::Room).must_equal true + end + + end +end diff --git a/spec/room_spec.rb b/spec/room_spec.rb index ae9c220ea..b311732b0 100644 --- a/spec/room_spec.rb +++ b/spec/room_spec.rb @@ -1 +1,12 @@ require_relative 'spec_helper' + +describe 'Room Wave 1' do + describe 'initialize' do + it 'creates a room number' do + new_room = Lodging::Room.new(46) + + expect(new_room).must_respond_to :room_number + expect(new_room).must_be_instance_of Lodging::Room + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1ffd49207..e2f0d7442 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -9,7 +9,7 @@ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new # Require_relative your lib files here! -require_relative 'lib/block' -require_relative 'lib/hotel' -require_relative 'lib/reservation' -require_relative 'lib/room' +require_relative '../lib/block' +require_relative '../lib/hotel' +require_relative '../lib/reservation' +require_relative '../lib/room' From 4f279b5653eb10789d9f42d2dfe13444e4cbc19c Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Wed, 5 Sep 2018 19:33:59 -0700 Subject: [PATCH 04/18] complete rehaul --- lib/admin.rb | 12 ++++++++ lib/block.rb | 7 ----- lib/hotel.rb | 35 ---------------------- lib/reservation.rb | 32 ++++++++++++++++---- lib/room.rb | 22 ++++++++------ spec/{block_spec.rb => admin_spec.rb} | 0 spec/hotel_spec.rb | 43 --------------------------- spec/room_spec.rb | 9 +++--- spec/spec_helper.rb | 6 ++-- 9 files changed, 59 insertions(+), 107 deletions(-) create mode 100644 lib/admin.rb delete mode 100644 lib/block.rb delete mode 100644 lib/hotel.rb rename spec/{block_spec.rb => admin_spec.rb} (100%) delete mode 100644 spec/hotel_spec.rb diff --git a/lib/admin.rb b/lib/admin.rb new file mode 100644 index 000000000..3bbdb6fd8 --- /dev/null +++ b/lib/admin.rb @@ -0,0 +1,12 @@ +#concierge can VIEW reservations +#concierge can RESERVE reservation +#concierge can ACCESS receipt for completed stay +#concierge can ACCESS hotel room list + +module Lodging #namespace + #similar to the main.rb of other projects + class Concierge #small hotels have concierges + + + end +end diff --git a/lib/block.rb b/lib/block.rb deleted file mode 100644 index e5de6e6d7..000000000 --- a/lib/block.rb +++ /dev/null @@ -1,7 +0,0 @@ -# module Lodging #name space to contain all info, including non-inherited classes -# class Block < Room #a special 'room' that is really a lot of unreserved rooms for 'vips' -# @rooms = rooms -# -# end -# -# end diff --git a/lib/hotel.rb b/lib/hotel.rb deleted file mode 100644 index f36426126..000000000 --- a/lib/hotel.rb +++ /dev/null @@ -1,35 +0,0 @@ -# require 'awesome_print' -# require_relative 'block' -# require_relative 'room' -# require_relative 'reservation' - -#can access list of all rooms in hotel? = yes -#can create new rooms automagically? = yes - -module Lodging #name space to contain all info, including non-inherited classes - class Hotel - attr_reader :name, :room_count, :rooms - - def initialize(hotel_name, room_count) - raise ArgumentError if room_count == nil || room_count <= 0 - - @name = hotel_name - @room_count = room_count - @rooms = create_rooms(room_count) - end - - def create_rooms(room_number) #method to create instances of room based on room_count - rooms = [] - room_number = 1 - - @room_count.times do - new_room = Room.new(room_number) - room_number += 1 - rooms << new_room - end - return rooms - end - - - end -end diff --git a/lib/reservation.rb b/lib/reservation.rb index 7d4420321..470f8b731 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -1,5 +1,27 @@ -# module Lodging #name space to contain all info, including non-inherited classes -# class Reservation #reservations apart from room -# end -# -# end +require 'awesome_print' +#reservation CREATES reservations +#reservation STORES reservations +#reservation TOTALS costs of stay + +module Lodging + + def room_status #check room_status + #if no room available, error + #else, reservation + + end + + def reservation #creates reservation + #check status, if available + #takes date range + #switches status to unavailable + # + end + + def receipt #calculates total cost of stay + #counts days in range + #multiply count by + + end + +end diff --git a/lib/room.rb b/lib/room.rb index 32f481097..a74247b9c 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,16 +1,20 @@ -# require_relative 'room' -# require_relative 'hotel' -# require_relative 'block' -# require_relative 'reservation' +require 'awesome_print' +#room should STORE room information +#room should STORE room status +#room should STORE room costs +#room should STORE all hotel rooms -module Lodging #name space to contain all info, including non-inherited classes +module Lodging class Room - attr_reader :room_number, :status, :cost - def initialize(room_number, cost = 200) #default price is 200/night - @room_number = room_number - @status = :AVAILABLE #available, unavailable, hold? + def initialize(room_count, cost = 200) + @room_count = room_count @cost = cost end + + def create_rooms + + end + end end diff --git a/spec/block_spec.rb b/spec/admin_spec.rb similarity index 100% rename from spec/block_spec.rb rename to spec/admin_spec.rb diff --git a/spec/hotel_spec.rb b/spec/hotel_spec.rb deleted file mode 100644 index 71ca64013..000000000 --- a/spec/hotel_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -require_relative 'spec_helper' - -describe 'Hotel Wave 1' do - describe 'initalize' do - it 'creates a hotel with attr name' do - my_hotel = Lodging::Hotel.new("My Hotel", 20) - - expect(my_hotel).must_respond_to :name - expect(my_hotel.name).must_equal "My Hotel" - - expect(my_hotel).must_respond_to :room_count - expect(my_hotel.room_count).must_equal 20 - - expect(my_hotel).must_respond_to :rooms - end - # - it 'errors if arg in rooms param is not an integer' do - expect{ - Lodging::Hotel.new("My Hotel","twenty") - }.must_raise ArgumentError - end - - it 'errors if arg for rooms param is 0' do - expect{ - Lodging::Hotel.new("My Hotel", 0) - }.must_raise ArgumentError - end - # - # it 'errors if arg in hotel_name param is not a string' do - # expect{ - # Lodging::Hotel.new(hotel49, 20) - # }.must_raise ArgumentError - # end - - it 'creates new Room class instances based on room_count' do - my_hotel = Lodging::Hotel.new("My Hotel", 20) - - expect(my_hotel.rooms).must_be_kind_of Array - expect(my_hotel.rooms.all? Lodging::Room).must_equal true - end - - end -end diff --git a/spec/room_spec.rb b/spec/room_spec.rb index b311732b0..fbb9f6835 100644 --- a/spec/room_spec.rb +++ b/spec/room_spec.rb @@ -1,12 +1,11 @@ require_relative 'spec_helper' -describe 'Room Wave 1' do +describe 'room class' do describe 'initialize' do - it 'creates a room number' do - new_room = Lodging::Room.new(46) + it 'creates a new instance of room' do + new_rooms = Lodging::Room.new(20) - expect(new_room).must_respond_to :room_number - expect(new_room).must_be_instance_of Lodging::Room + expect(new_rooms).must_be_instance_of Lodging::Room end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e2f0d7442..a01555818 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,5 @@ #### -require 'simplecov' +require 'simplecov' #for autotesting w. guard SimpleCov.start #### require 'minitest' @@ -9,7 +9,7 @@ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new # Require_relative your lib files here! -require_relative '../lib/block' -require_relative '../lib/hotel' +# require_relative '../lib/block' +require_relative '../lib/admin' require_relative '../lib/reservation' require_relative '../lib/room' From 04272bc1ba1dbb70fc4d1f55d3b06f4794ddc5f8 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Thu, 6 Sep 2018 16:29:41 -0700 Subject: [PATCH 05/18] can create rooms, assign each number - tests passed --- lib/admin.rb | 8 +++++++- lib/lodging.rb | 15 +++++++++++++++ lib/room.rb | 23 +++++++++++++++-------- spec/admin_spec.rb | 10 ++++++++++ spec/lodging_spec.rb | 26 ++++++++++++++++++++++++++ spec/room_spec.rb | 20 ++++++++++++++++++++ spec/spec_helper.rb | 1 + 7 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 lib/lodging.rb create mode 100644 spec/lodging_spec.rb diff --git a/lib/admin.rb b/lib/admin.rb index 3bbdb6fd8..cab278ccd 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -1,4 +1,5 @@ -#concierge can VIEW reservations +require 'awesome_print' +#concierge can VIEW reservations #concierge can RESERVE reservation #concierge can ACCESS receipt for completed stay #concierge can ACCESS hotel room list @@ -7,6 +8,11 @@ module Lodging #namespace #similar to the main.rb of other projects class Concierge #small hotels have concierges + def self.all_rooms + print Room.show_list + + end + end end diff --git a/lib/lodging.rb b/lib/lodging.rb new file mode 100644 index 000000000..0882303ee --- /dev/null +++ b/lib/lodging.rb @@ -0,0 +1,15 @@ +#module methods go here +require_relative 'room' +module Lodging + + #creates multiple rooms at once, and assigns room number + def self.create_rooms(room_count, cost = 200) #creates new rooms, assigns room no. + raise ArgumentError if !room_count.is_a? Integer + i = 1 + room_count.times do + Room.new(i, cost) + i += 1 + end + end + +end diff --git a/lib/room.rb b/lib/room.rb index a74247b9c..fe6ef8fe5 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -1,19 +1,26 @@ require 'awesome_print' -#room should STORE room information -#room should STORE room status -#room should STORE room costs -#room should STORE all hotel rooms +#room should CREATE ROOMS = yes +#room should STORE room information = yes +#room should STORE room status = yes +#room should STORE room costs = yes +#room should STORE all hotel rooms = yes module Lodging + class Room + attr_reader :room_number + + @@room_list = [] #to store all instances of rooms created - def initialize(room_count, cost = 200) - @room_count = room_count + def initialize(room_number, cost = 200) + @room_number = room_number @cost = cost + @status = :available + @@room_list << self end - def create_rooms - + def self.show_list #to show list as instances + return @@room_list end end diff --git a/spec/admin_spec.rb b/spec/admin_spec.rb index ae9c220ea..e09524278 100644 --- a/spec/admin_spec.rb +++ b/spec/admin_spec.rb @@ -1 +1,11 @@ require_relative 'spec_helper' + +describe 'Concierge class' do + describe 'all_rooms method' do + it 'shows all rooms in hotel' do + Lodging::Room.new(10) + + Lodging::Concierge.all_rooms + end + end +end diff --git a/spec/lodging_spec.rb b/spec/lodging_spec.rb new file mode 100644 index 000000000..e1017ecd0 --- /dev/null +++ b/spec/lodging_spec.rb @@ -0,0 +1,26 @@ +require_relative 'spec_helper' + + + describe 'create rooms' do + it 'creates mulitiple instances of room' do + Lodging.create_rooms(10) + + expect(Lodging::Room.show_list).must_be_instance_of Array + expect(Lodging::Room.show_list.any? Lodging::Room).must_equal true + end + + it 'assigns different room numbers to each instance up to x times' do + Lodging.create_rooms(10) + first = Lodging::Room.show_list.first + last = Lodging::Room.show_list.last + + expect(Lodging::Room.show_list.length).must_equal 10 + expect(first.room_number).must_equal 1 + expect(last.room_number).must_equal 10 + end + + it 'errrors if argument passed is not integer' do + expect{Lodging.create_rooms('forty')}.must_raise ArgumentError + expect{Lodging.create_rooms(3.5)}.must_raise ArgumentError + end + end diff --git a/spec/room_spec.rb b/spec/room_spec.rb index fbb9f6835..eb49e869a 100644 --- a/spec/room_spec.rb +++ b/spec/room_spec.rb @@ -1,6 +1,9 @@ require_relative 'spec_helper' describe 'room class' do + #clears the class variable back to empty array before each test + before(:each) { Lodging::Room.class_variable_set :@@room_list, [] } + describe 'initialize' do it 'creates a new instance of room' do new_rooms = Lodging::Room.new(20) @@ -8,4 +11,21 @@ expect(new_rooms).must_be_instance_of Lodging::Room end end + + describe 'show list' do + it 'prints all instances of room' do + Lodging.create_rooms(10) + + list = Lodging::Room.show_list + first = list.first + last = list.last + + expect(list.length).must_equal 10 + expect(list.any? Lodging::Room).must_equal true + + expect(first.room_number).must_equal 1 + expect(last.room_number).must_equal 10 + end + end + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a01555818..3ae828348 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,6 +10,7 @@ # Require_relative your lib files here! # require_relative '../lib/block' +require_relative '../lib/lodging' require_relative '../lib/admin' require_relative '../lib/reservation' require_relative '../lib/room' From 714e9d147df08b2fa0912874f7a4ddb2ddb511c6 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Thu, 6 Sep 2018 16:37:05 -0700 Subject: [PATCH 06/18] can view all rooms / for spec, class var cleared before tests --- lib/admin.rb | 7 ++++--- lib/room.rb | 2 +- spec/admin_spec.rb | 4 +++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index cab278ccd..bc87f47d5 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -2,15 +2,16 @@ #concierge can VIEW reservations #concierge can RESERVE reservation #concierge can ACCESS receipt for completed stay -#concierge can ACCESS hotel room list +#concierge can ACCESS hotel room list = yes module Lodging #namespace #similar to the main.rb of other projects class Concierge #small hotels have concierges def self.all_rooms - print Room.show_list - + Room.show_list.each do |room| + ap "Room #{room.room_number} costs $#{room.cost} a night and is #{room.status}." + end end diff --git a/lib/room.rb b/lib/room.rb index fe6ef8fe5..3dc1cc3c0 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -8,7 +8,7 @@ module Lodging class Room - attr_reader :room_number + attr_reader :room_number, :status, :cost @@room_list = [] #to store all instances of rooms created diff --git a/spec/admin_spec.rb b/spec/admin_spec.rb index e09524278..8d981e030 100644 --- a/spec/admin_spec.rb +++ b/spec/admin_spec.rb @@ -1,9 +1,11 @@ require_relative 'spec_helper' describe 'Concierge class' do + before(:each) { Lodging::Room.class_variable_set :@@room_list, [] } + describe 'all_rooms method' do it 'shows all rooms in hotel' do - Lodging::Room.new(10) + Lodging.create_rooms(10) Lodging::Concierge.all_rooms end From d3848923909f55b1d7460cffc8badbd5dfb30afd Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Thu, 6 Sep 2018 17:33:07 -0700 Subject: [PATCH 07/18] can check availability --- lib/admin.rb | 12 ++++++++- lib/lodging.rb | 6 ++--- lib/reservation.rb | 14 +++++------ spec/admin_spec.rb | 9 +++++-- spec/lodging_spec.rb | 6 ++++- spec/reservation_spec.rb | 54 ++++++++++++++++++++++++++++++++++++++++ spec/room_spec.rb | 4 ++- 7 files changed, 90 insertions(+), 15 deletions(-) diff --git a/lib/admin.rb b/lib/admin.rb index bc87f47d5..096f0972d 100644 --- a/lib/admin.rb +++ b/lib/admin.rb @@ -7,11 +7,21 @@ module Lodging #namespace #similar to the main.rb of other projects class Concierge #small hotels have concierges + attr_accessor :room_hash + + @room_hash = [] def self.all_rooms Room.show_list.each do |room| - ap "Room #{room.room_number} costs $#{room.cost} a night and is #{room.status}." + 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 diff --git a/lib/lodging.rb b/lib/lodging.rb index 0882303ee..53a9d9e1c 100644 --- a/lib/lodging.rb +++ b/lib/lodging.rb @@ -1,5 +1,5 @@ -#module methods go here -require_relative 'room' +require 'awesome_print' + module Lodging #creates multiple rooms at once, and assigns room number @@ -11,5 +11,5 @@ def self.create_rooms(room_count, cost = 200) #creates new rooms, assigns room n i += 1 end end - + end diff --git a/lib/reservation.rb b/lib/reservation.rb index 470f8b731..cff4968df 100644 --- a/lib/reservation.rb +++ b/lib/reservation.rb @@ -5,20 +5,20 @@ module Lodging - def room_status #check room_status - #if no room available, error - #else, reservation - + def self.room_status(input) #check room_status + input.find do |room| + room[:status] == :available #returns first instance it finds of available room + end end - def reservation #creates reservation - #check status, if available + def self.reservation #creates reservation + #check status, if available #takes date range #switches status to unavailable # end - def receipt #calculates total cost of stay + def self.receipt #calculates total cost of stay #counts days in range #multiply count by diff --git a/spec/admin_spec.rb b/spec/admin_spec.rb index 8d981e030..2ae512715 100644 --- a/spec/admin_spec.rb +++ b/spec/admin_spec.rb @@ -1,13 +1,18 @@ require_relative 'spec_helper' describe 'Concierge class' do - before(:each) { Lodging::Room.class_variable_set :@@room_list, [] } + before(:each) do + Lodging::Room.class_variable_set(:@@room_list, []) + end describe 'all_rooms method' do it 'shows all rooms in hotel' do Lodging.create_rooms(10) - Lodging::Concierge.all_rooms + room_list = Lodging::Concierge.all_rooms + + expect(room_list.any? Hash).must_equal true + # expect(room_list.length).must_equal 10 end end end diff --git a/spec/lodging_spec.rb b/spec/lodging_spec.rb index e1017ecd0..a501e482f 100644 --- a/spec/lodging_spec.rb +++ b/spec/lodging_spec.rb @@ -2,6 +2,10 @@ describe 'create rooms' do + before(:each) do + Lodging::Room.class_variable_set(:@@room_list, []) + end + it 'creates mulitiple instances of room' do Lodging.create_rooms(10) @@ -19,7 +23,7 @@ expect(last.room_number).must_equal 10 end - it 'errrors if argument passed is not integer' do + it 'errors if argument passed is not integer' do expect{Lodging.create_rooms('forty')}.must_raise ArgumentError expect{Lodging.create_rooms(3.5)}.must_raise ArgumentError end diff --git a/spec/reservation_spec.rb b/spec/reservation_spec.rb index ae9c220ea..e2853a373 100644 --- a/spec/reservation_spec.rb +++ b/spec/reservation_spec.rb @@ -1 +1,55 @@ require_relative 'spec_helper' + +describe 'Lodging Reservation' do + before(:each) do + Lodging::Room.class_variable_set(:@@room_list, []) + end + + describe 'check status' do + before do + Lodging.create_rooms(5) + end + + it 'errors if all rooms are unavailable' do + rooms = Lodging.room_status(Lodging::Concierge.all_rooms) + + + + + end + + it 'returns one available room if no error' do + avail = Lodging.room_status(Lodging::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 'returns date range of reservation' do + + end + + it 'errors if invalid date range' 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 diff --git a/spec/room_spec.rb b/spec/room_spec.rb index eb49e869a..0f2caa4c1 100644 --- a/spec/room_spec.rb +++ b/spec/room_spec.rb @@ -2,7 +2,9 @@ describe 'room class' do #clears the class variable back to empty array before each test - before(:each) { Lodging::Room.class_variable_set :@@room_list, [] } + before(:each) do + Lodging::Room.class_variable_set(:@@room_list, []) + end describe 'initialize' do it 'creates a new instance of room' do From 33f563f4cf77fee8107d4684367556ed91eee0e7 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Sat, 8 Sep 2018 14:29:01 -0700 Subject: [PATCH 08/18] now data stored in csvs --- all hotel rooms.csv | 11 +++++++ data/all hotel rooms.csv | 1 + junk/admin.rb | 62 ++++++++++++++++++++++++++++++++++++ junk/admin_spec.rb | 45 ++++++++++++++++++++++++++ junk/reservation.rb | 42 +++++++++++++++++++++++++ junk/reservation_spec.rb | 60 +++++++++++++++++++++++++++++++++++ lib/admin.rb | 29 ----------------- lib/concierge.rb | 34 ++++++++++++++++++++ lib/lodging.rb | 1 - lib/reservation.rb | 27 ---------------- lib/room.rb | 12 +++---- spec/admin_spec.rb | 18 ----------- spec/concierge_spec.rb | 22 +++++++++++++ spec/lodging_spec.rb | 68 ++++++++++++++++++++++------------------ spec/reservation_spec.rb | 55 -------------------------------- spec/room_spec.rb | 31 +++++++++--------- spec/spec_helper.rb | 4 +-- 17 files changed, 338 insertions(+), 184 deletions(-) create mode 100644 all hotel rooms.csv create mode 100644 data/all hotel rooms.csv create mode 100644 junk/admin.rb create mode 100644 junk/admin_spec.rb create mode 100644 junk/reservation.rb create mode 100644 junk/reservation_spec.rb delete mode 100644 lib/admin.rb create mode 100644 lib/concierge.rb delete mode 100644 lib/reservation.rb delete mode 100644 spec/admin_spec.rb create mode 100644 spec/concierge_spec.rb delete mode 100644 spec/reservation_spec.rb diff --git a/all hotel rooms.csv b/all hotel rooms.csv new file mode 100644 index 000000000..74b97423e --- /dev/null +++ b/all hotel rooms.csv @@ -0,0 +1,11 @@ +room_number,cost,status +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 diff --git a/data/all hotel rooms.csv b/data/all hotel rooms.csv new file mode 100644 index 000000000..0ba6a5074 --- /dev/null +++ b/data/all hotel rooms.csv @@ -0,0 +1 @@ +room_number,cost,status diff --git a/junk/admin.rb b/junk/admin.rb new file mode 100644 index 000000000..97c7eca3b --- /dev/null +++ b/junk/admin.rb @@ -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 diff --git a/junk/admin_spec.rb b/junk/admin_spec.rb new file mode 100644 index 000000000..ad14d77f3 --- /dev/null +++ b/junk/admin_spec.rb @@ -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 diff --git a/junk/reservation.rb b/junk/reservation.rb new file mode 100644 index 000000000..0c26d6fd3 --- /dev/null +++ b/junk/reservation.rb @@ -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 diff --git a/junk/reservation_spec.rb b/junk/reservation_spec.rb new file mode 100644 index 000000000..682c78ae5 --- /dev/null +++ b/junk/reservation_spec.rb @@ -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 diff --git a/lib/admin.rb b/lib/admin.rb deleted file mode 100644 index 096f0972d..000000000 --- a/lib/admin.rb +++ /dev/null @@ -1,29 +0,0 @@ -require 'awesome_print' -#concierge can VIEW reservations -#concierge can RESERVE reservation -#concierge can ACCESS receipt for completed stay -#concierge can ACCESS hotel room list = yes - -module Lodging #namespace - #similar to the main.rb of other projects - class Concierge #small hotels have concierges - attr_accessor :room_hash - - @room_hash = [] - - def self.all_rooms - 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 - - - end -end diff --git a/lib/concierge.rb b/lib/concierge.rb new file mode 100644 index 000000000..4bbf30434 --- /dev/null +++ b/lib/concierge.rb @@ -0,0 +1,34 @@ +require 'awesome_print' +require 'date' +require 'csv' +#concierge can ACCESS list of all rooms in hotel +#concierge can RESERVE reservation for date range +#concierge can ACCESS list of reservations on date +#concierge can ACCESS receipt for completed stay +#can datevar.strftime("%b %d, %Y") + +module Lodging + + class Concierge + attr_accessor :room_hash + + def initialize(room_count) + Lodging.create_rooms(room_count) #creating rooms upon initialization + end + + def all_rooms + CSV.read('all hotel rooms.csv', headers: true).each do |room| + print room + end + end + + def new_reservation(check_in, check_out) + raise ArgumentError if Date.parse(check_out) < Date.parse(check_in) + + book_this = Lodging.reservation(all_rooms, status) + book_this[:check_in] = Date.parse(check_in) + book_this[:check_out] = Date.parse(check_out) + + end + end +end diff --git a/lib/lodging.rb b/lib/lodging.rb index 53a9d9e1c..b8f0744aa 100644 --- a/lib/lodging.rb +++ b/lib/lodging.rb @@ -11,5 +11,4 @@ def self.create_rooms(room_count, cost = 200) #creates new rooms, assigns room n i += 1 end end - end diff --git a/lib/reservation.rb b/lib/reservation.rb deleted file mode 100644 index cff4968df..000000000 --- a/lib/reservation.rb +++ /dev/null @@ -1,27 +0,0 @@ -require 'awesome_print' -#reservation CREATES reservations -#reservation STORES reservations -#reservation TOTALS costs of stay - -module Lodging - - def self.room_status(input) #check room_status - input.find do |room| - room[:status] == :available #returns first instance it finds of available room - end - end - - def self.reservation #creates reservation - #check status, if available - #takes date range - #switches status to unavailable - # - end - - def self.receipt #calculates total cost of stay - #counts days in range - #multiply count by - - end - -end diff --git a/lib/room.rb b/lib/room.rb index 3dc1cc3c0..407527d77 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -10,17 +10,17 @@ module Lodging class Room attr_reader :room_number, :status, :cost - @@room_list = [] #to store all instances of rooms created - def initialize(room_number, cost = 200) @room_number = room_number @cost = cost @status = :available - @@room_list << self - end - def self.show_list #to show list as instances - return @@room_list + room = [@room_number, @cost, @status] + + CSV.open('all hotel rooms.csv', 'a+') do |row| + row << room + end + end end diff --git a/spec/admin_spec.rb b/spec/admin_spec.rb deleted file mode 100644 index 2ae512715..000000000 --- a/spec/admin_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require_relative 'spec_helper' - -describe 'Concierge class' do - before(:each) do - Lodging::Room.class_variable_set(:@@room_list, []) - end - - describe 'all_rooms method' do - it 'shows all rooms in hotel' do - Lodging.create_rooms(10) - - room_list = Lodging::Concierge.all_rooms - - expect(room_list.any? Hash).must_equal true - # expect(room_list.length).must_equal 10 - end - end -end diff --git a/spec/concierge_spec.rb b/spec/concierge_spec.rb new file mode 100644 index 000000000..8ad1a3458 --- /dev/null +++ b/spec/concierge_spec.rb @@ -0,0 +1,22 @@ +require_relative 'spec_helper' + +describe 'Concierge class' do + #reset CSV data + before(:each) do + CSV.open('all hotel rooms.csv', 'w', headers: true) do |csv| + csv << ['room_number','cost','status'] + end + end + + let(:concierge){ + Lodging::Concierge.new(10) + } + + it 'can view data in all hotel rooms csv file' do + + expect(concierge.all_rooms).must_be_instance_of CSV::Table + expect(concierge.all_rooms.length).must_equal 10 + + end + +end diff --git a/spec/lodging_spec.rb b/spec/lodging_spec.rb index a501e482f..3f78f0d0e 100644 --- a/spec/lodging_spec.rb +++ b/spec/lodging_spec.rb @@ -1,30 +1,38 @@ -require_relative 'spec_helper' - - - describe 'create rooms' do - before(:each) do - Lodging::Room.class_variable_set(:@@room_list, []) - end - - it 'creates mulitiple instances of room' do - Lodging.create_rooms(10) - - expect(Lodging::Room.show_list).must_be_instance_of Array - expect(Lodging::Room.show_list.any? Lodging::Room).must_equal true - end - - it 'assigns different room numbers to each instance up to x times' do - Lodging.create_rooms(10) - first = Lodging::Room.show_list.first - last = Lodging::Room.show_list.last - - expect(Lodging::Room.show_list.length).must_equal 10 - expect(first.room_number).must_equal 1 - expect(last.room_number).must_equal 10 - end - - it 'errors if argument passed is not integer' do - expect{Lodging.create_rooms('forty')}.must_raise ArgumentError - expect{Lodging.create_rooms(3.5)}.must_raise ArgumentError - end - end +# require_relative 'spec_helper' +# +# describe 'Lodging module methods' do +# +# describe 'create rooms' do +# before(:each) do +# Lodging::Room.class_variable_set(:@@room_list, []) +# end +# +# let(:concierge) { +# Lodging::Concierge.new(10) +# } ##uses the create_rooms method +# +# it 'creates mulitiple instances of room' do +# concierge +# +# expect(Lodging::Room.show_list).must_be_instance_of Array +# expect(Lodging::Room.show_list.any? Lodging::Room).must_equal true +# +# expect(concierge.all_rooms.length).must_equal 10 +# end +# +# it 'assigns different room numbers to each instance up to x times' do +# Lodging.create_rooms(10) +# first = Lodging::Room.show_list.first +# last = Lodging::Room.show_list.last +# +# expect(Lodging::Room.show_list.length).must_equal 10 +# expect(first.room_number).must_equal 1 +# expect(last.room_number).must_equal 10 +# end +# +# it 'errors if argument passed is not integer' do +# expect{Lodging.create_rooms('forty')}.must_raise ArgumentError +# expect{Lodging.create_rooms(3.5)}.must_raise ArgumentError +# end +# end +# end diff --git a/spec/reservation_spec.rb b/spec/reservation_spec.rb deleted file mode 100644 index e2853a373..000000000 --- a/spec/reservation_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -require_relative 'spec_helper' - -describe 'Lodging Reservation' do - before(:each) do - Lodging::Room.class_variable_set(:@@room_list, []) - end - - describe 'check status' do - before do - Lodging.create_rooms(5) - end - - it 'errors if all rooms are unavailable' do - rooms = Lodging.room_status(Lodging::Concierge.all_rooms) - - - - - end - - it 'returns one available room if no error' do - avail = Lodging.room_status(Lodging::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 'returns date range of reservation' do - - end - - it 'errors if invalid date range' 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 diff --git a/spec/room_spec.rb b/spec/room_spec.rb index 0f2caa4c1..a30909bef 100644 --- a/spec/room_spec.rb +++ b/spec/room_spec.rb @@ -1,33 +1,32 @@ require_relative 'spec_helper' describe 'room class' do - #clears the class variable back to empty array before each test + #to clear CSV file before each test before(:each) do - Lodging::Room.class_variable_set(:@@room_list, []) + CSV.open('all hotel rooms.csv', 'w', headers: true) do |csv| + csv << ['room_number','cost','status'] end +end + describe 'initialize' do it 'creates a new instance of room' do - new_rooms = Lodging::Room.new(20) + new_room = Lodging::Room.new(3, 250) - expect(new_rooms).must_be_instance_of Lodging::Room + expect(new_room).must_be_instance_of Lodging::Room + expect(new_room.room_number).must_equal 3 + expect(new_room.cost).must_equal 250 + expect(new_room.status).must_equal :available end end - describe 'show list' do - it 'prints all instances of room' do - Lodging.create_rooms(10) + it 'adds each new instance of room into csv file' do + Lodging.create_rooms(5) - list = Lodging::Room.show_list - first = list.first - last = list.last + rooms = CSV.read('all hotel rooms.csv', headers: true) - expect(list.length).must_equal 10 - expect(list.any? Lodging::Room).must_equal true - - expect(first.room_number).must_equal 1 - expect(last.room_number).must_equal 10 - end + expect(rooms).must_be_instance_of CSV::Table + expect(rooms.length).must_equal 5 end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3ae828348..90c840106 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -11,6 +11,6 @@ # Require_relative your lib files here! # require_relative '../lib/block' require_relative '../lib/lodging' -require_relative '../lib/admin' -require_relative '../lib/reservation' +require_relative '../lib/concierge' +# require_relative '../lib/reservation' require_relative '../lib/room' From 211253fd1edbae4f50f34ad2d7abb01c9d7d8a96 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Sat, 8 Sep 2018 14:29:29 -0700 Subject: [PATCH 09/18] ignore folder done --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5e1422c9c..085efd0a6 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ /test/tmp/ /test/version_tmp/ /tmp/ +/junk/ # Used by dotenv library to load environment variables. # .env From c76b65709819a6747b1cd6543e7d57bec1735c18 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Sun, 9 Sep 2018 14:31:59 -0700 Subject: [PATCH 10/18] can receipt, can view reserved by date --- all hotel rooms.csv | 11 ------ data/all hotel rooms.csv | 1 - data/all_hotel_rooms.csv | 11 ++++++ data/reservations.csv | 1 + lib/concierge.rb | 76 ++++++++++++++++++++++++++++++++------- lib/lodging.rb | 20 +++++++++++ lib/room.rb | 11 ++++-- spec/concierge_spec.rb | 78 ++++++++++++++++++++++++++++++++++++---- spec/lodging_spec.rb | 3 -- spec/room_spec.rb | 23 +++++++++--- spec/spec_helper.rb | 1 - 11 files changed, 194 insertions(+), 42 deletions(-) delete mode 100644 all hotel rooms.csv delete mode 100644 data/all hotel rooms.csv create mode 100644 data/all_hotel_rooms.csv create mode 100644 data/reservations.csv diff --git a/all hotel rooms.csv b/all hotel rooms.csv deleted file mode 100644 index 74b97423e..000000000 --- a/all hotel rooms.csv +++ /dev/null @@ -1,11 +0,0 @@ -room_number,cost,status -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 diff --git a/data/all hotel rooms.csv b/data/all hotel rooms.csv deleted file mode 100644 index 0ba6a5074..000000000 --- a/data/all hotel rooms.csv +++ /dev/null @@ -1 +0,0 @@ -room_number,cost,status diff --git a/data/all_hotel_rooms.csv b/data/all_hotel_rooms.csv new file mode 100644 index 000000000..c214476ab --- /dev/null +++ b/data/all_hotel_rooms.csv @@ -0,0 +1,11 @@ +room_number,cost,status,check_in,check_out +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,, diff --git a/data/reservations.csv b/data/reservations.csv new file mode 100644 index 000000000..14a18c447 --- /dev/null +++ b/data/reservations.csv @@ -0,0 +1 @@ +room_number,cost,status,check_in,check_out diff --git a/lib/concierge.rb b/lib/concierge.rb index 4bbf30434..b37b68740 100644 --- a/lib/concierge.rb +++ b/lib/concierge.rb @@ -1,34 +1,84 @@ require 'awesome_print' require 'date' require 'csv' -#concierge can ACCESS list of all rooms in hotel -#concierge can RESERVE reservation for date range -#concierge can ACCESS list of reservations on date -#concierge can ACCESS receipt for completed stay -#can datevar.strftime("%b %d, %Y") +require_relative 'lodging' +require_relative 'room' +#concierge can ACCESS list of all rooms in hotel = yes +#concierge can RESERVE reservation for date range = yes +#concierge can RESERVE new res. on last day of prev. one +#concierge can ACCESS list of reservations on date = yes +#concierge can ACCESS receipt for completed stay = yes +#receipt does NOT INCLUDE last day = yes +#can view rooms NOT RESERVED on date +#datevar.strftime("%b %d, %Y") - date output module Lodging class Concierge - attr_accessor :room_hash + + attr_accessor :rooms_info def initialize(room_count) Lodging.create_rooms(room_count) #creating rooms upon initialization + + rooms = CSV.read('data/all_hotel_rooms.csv', headers: true, header_converters: :symbol).map do |room| + room.to_h + end + @rooms_info = rooms end def all_rooms - CSV.read('all hotel rooms.csv', headers: true).each do |room| - print room + return @rooms_info + end + + def new_reservation(check_in, check_out) #makes new reservation based on two dates + + raise ArgumentError if Date.parse(check_out) < Date.parse(check_in) #checkout cannot be earlier than check in + + book_this = Lodging.room_status(@rooms_info) #returns one availalbe room + + reserved_dates = Lodging.create_date_range(check_in, check_out) #parses range for date, into array + + update_room = @rooms_info.find do |room| + room[:room_number] == book_this[:room_number] + end #finds room to be reserved + + update_room[:status] = "unavailable" #changes status of said room in the array of hashes as 'unavailable' + update_room[:reserved_dates] = reserved_dates + + end + # + def reserved_rooms(date) #see list of reserved rooms by date + + raise ArgumentError if !Date.parse(date).instance_of? Date + + search_date = Date.parse(date) + + reserved_rooms = @rooms_info.find_all do |room| + room if room[:reserved_dates] end + + reserved_room_list = reserved_rooms.select do |room| + room if room[:reserved_dates].include? search_date + end + + return reserved_room_list + + end - def new_reservation(check_in, check_out) - raise ArgumentError if Date.parse(check_out) < Date.parse(check_in) + def receipt(room_number) #date step method to determine day count + check_out_room = @rooms_info.find do |room| + room_number.to_s == room[:room_number] + end + + cost = check_out_room[:cost].to_f + total_days = check_out_room[:reserved_dates].length - 1 - book_this = Lodging.reservation(all_rooms, status) - book_this[:check_in] = Date.parse(check_in) - book_this[:check_out] = Date.parse(check_out) + return (cost * total_days).round(2) end + + end end diff --git a/lib/lodging.rb b/lib/lodging.rb index b8f0744aa..96913a4ec 100644 --- a/lib/lodging.rb +++ b/lib/lodging.rb @@ -11,4 +11,24 @@ def self.create_rooms(room_count, cost = 200) #creates new rooms, assigns room n i += 1 end end + + def self.total_owed #totals cost of length of stay + puts "sup" + end + +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 + + raise ArgumentError if avail == false + + return avail +end + +def self.create_date_range(date1, date2) + return (Date.parse(date1)..Date.parse(date2)).to_a +end + + end diff --git a/lib/room.rb b/lib/room.rb index 407527d77..b01507fef 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -3,7 +3,7 @@ #room should STORE room information = yes #room should STORE room status = yes #room should STORE room costs = yes -#room should STORE all hotel rooms = yes +#room should STORE all_hotel_rooms = yes module Lodging @@ -15,12 +15,17 @@ def initialize(room_number, cost = 200) @cost = cost @status = :available - room = [@room_number, @cost, @status] + room = [@room_number, @cost, @status, nil, nil] - CSV.open('all hotel rooms.csv', 'a+') do |row| + CSV.open('data/all_hotel_rooms.csv', 'a+') do |row| row << room end + end + def self.available_room #to return one room with status available + CSV.open('data/all_hotel_rooms.csv', 'r', headers: true) do |row| + return row + end end end diff --git a/spec/concierge_spec.rb b/spec/concierge_spec.rb index 8ad1a3458..e5f1032fb 100644 --- a/spec/concierge_spec.rb +++ b/spec/concierge_spec.rb @@ -1,10 +1,14 @@ require_relative 'spec_helper' -describe 'Concierge class' do +describe 'Lodging::Concierge class' do #reset CSV data before(:each) do - CSV.open('all hotel rooms.csv', 'w', headers: true) do |csv| - csv << ['room_number','cost','status'] + CSV.open('data/all_hotel_rooms.csv', 'w', headers: true) do |csv| + csv << ['room_number','cost','status','check_in','check_out'] + end + + CSV.open('data/reservations.csv', 'w', headers: true) do |csv| + csv << ['room_number','cost','status','check_in','check_out'] end end @@ -12,11 +16,73 @@ Lodging::Concierge.new(10) } - it 'can view data in all hotel rooms csv file' do + describe 'all rooms method' do + it 'can view data in all_hotel_rooms csv file' do + + expect(concierge.all_rooms).must_be_instance_of Array + expect(concierge.all_rooms.any? Hash).must_equal true + expect(concierge.all_rooms.length).must_equal 10 + + end + end + + describe 'new reservation method' do + + it 'creates new reservations' do + concierge.all_rooms + + concierge.new_reservation('Sept 9, 2018', 'Sept 12, 2018') + + first = concierge.all_rooms[0][:reserved_dates].first + last = concierge.all_rooms[0][:reserved_dates].last + status = concierge.all_rooms[0][:status] + + expect(status).must_equal 'unavailable' + expect(first).must_equal Date.parse('Sept 9, 2018') + expect(last).must_equal Date.parse('Sept 12, 2018') + + end + + it 'errors if invalid date is entered' do + expect{concierge.new_reservation('August 7, 2019', 'August 28, 2018')}.must_raise ArgumentError + end + + end + + describe 'reserved rooms method' do + it 'errors if date argument not passed' do + concierge.new_reservation('Sept 9, 2018', 'Sept 12, 2018') + concierge.new_reservation('Sept 13, 2018', 'Sept 20, 2018') + + expect{concierge.reserved_rooms('forty-two')}.must_raise ArgumentError + expect{concierge.reserved_rooms(4)}.must_raise TypeError + expect{concierge.reserved_rooms('66')}.must_raise ArgumentError + + end - expect(concierge.all_rooms).must_be_instance_of CSV::Table - expect(concierge.all_rooms.length).must_equal 10 + it 'returns list of reservations that have date' do + concierge.new_reservation('Sept 9, 2018', 'Sept 12, 2018') #room 1 + concierge.new_reservation('Sept 13, 2018', 'Sept 20, 2018') #room 2 + concierge.new_reservation('Sept 10, 2018', 'Sept 20, 2018') #room 3 + concierge.new_reservation('Sept 6, 2018', 'Sept 13, 2018') #room 4 + sept_12 = concierge.reserved_rooms('Sept 12, 2018') + + expect(sept_12.length).must_equal 3 + expect(sept_12[0][:room_number]).must_equal '1' + expect(sept_12[1][:room_number]).must_equal '3' + expect(sept_12[2][:room_number]).must_equal '4' + + end + + end + + describe 'receipt' do + it 'calculates total cost for stay' do + concierge.new_reservation('Sept 9, 2018', 'Sept 12, 2018') #room 1 + + concierge.receipt(1) + end end end diff --git a/spec/lodging_spec.rb b/spec/lodging_spec.rb index 3f78f0d0e..0df6d12bb 100644 --- a/spec/lodging_spec.rb +++ b/spec/lodging_spec.rb @@ -3,9 +3,6 @@ # describe 'Lodging module methods' do # # describe 'create rooms' do -# before(:each) do -# Lodging::Room.class_variable_set(:@@room_list, []) -# end # # let(:concierge) { # Lodging::Concierge.new(10) diff --git a/spec/room_spec.rb b/spec/room_spec.rb index a30909bef..df162107e 100644 --- a/spec/room_spec.rb +++ b/spec/room_spec.rb @@ -3,11 +3,14 @@ describe 'room class' do #to clear CSV file before each test before(:each) do - CSV.open('all hotel rooms.csv', 'w', headers: true) do |csv| + CSV.open('data/all_hotel_rooms.csv', 'w', headers: true) do |csv| csv << ['room_number','cost','status'] - end -end + end + CSV.open('data/reservations.csv', 'w', headers: true) do |csv| + csv << ['room_number','cost','status','check_in','check_out'] + end + end describe 'initialize' do it 'creates a new instance of room' do @@ -23,10 +26,22 @@ it 'adds each new instance of room into csv file' do Lodging.create_rooms(5) - rooms = CSV.read('all hotel rooms.csv', headers: true) + rooms = CSV.read('data/all_hotel_rooms.csv', headers: true) expect(rooms).must_be_instance_of CSV::Table expect(rooms.length).must_equal 5 end + describe 'available room' do + # let(:new_room) { + # CSV.read('all_hotel_rooms.csv', headers: true) + # } + + it 'returns CSV row of available room' do + Lodging.create_rooms(5) + + expect(Lodging::Room.available_room).must_be_instance_of CSV::Row + end + end + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 90c840106..783edf820 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,5 +12,4 @@ # require_relative '../lib/block' require_relative '../lib/lodging' require_relative '../lib/concierge' -# require_relative '../lib/reservation' require_relative '../lib/room' From 343e9801a7b7625837ee7e39cf2d3d5eeac63029 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Mon, 10 Sep 2018 07:24:55 -0700 Subject: [PATCH 11/18] can block reserve, can block hold --- data/all_hotel_rooms.csv | 22 +++++----- lib/concierge.rb | 69 +++++++++++++++++++++++++++----- lib/lodging.rb | 15 +++---- lib/room.rb | 4 +- refactors.txt | 1 + spec/concierge_spec.rb | 86 +++++++++++++++++++++++++++++++++++++++- spec/lodging_spec.rb | 36 +---------------- spec/room_spec.rb | 9 ++--- 8 files changed, 170 insertions(+), 72 deletions(-) create mode 100644 refactors.txt diff --git a/data/all_hotel_rooms.csv b/data/all_hotel_rooms.csv index c214476ab..c51ed7db9 100644 --- a/data/all_hotel_rooms.csv +++ b/data/all_hotel_rooms.csv @@ -1,11 +1,11 @@ -room_number,cost,status,check_in,check_out -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,, +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,[] diff --git a/lib/concierge.rb b/lib/concierge.rb index b37b68740..125a39c44 100644 --- a/lib/concierge.rb +++ b/lib/concierge.rb @@ -1,6 +1,8 @@ require 'awesome_print' require 'date' require 'csv' +require 'pry' + require_relative 'lodging' require_relative 'room' #concierge can ACCESS list of all rooms in hotel = yes @@ -9,7 +11,8 @@ #concierge can ACCESS list of reservations on date = yes #concierge can ACCESS receipt for completed stay = yes #receipt does NOT INCLUDE last day = yes -#can view rooms NOT RESERVED on date +#can view rooms NOT RESERVED on date = yes +#can block reservation = yes #datevar.strftime("%b %d, %Y") - date output module Lodging @@ -21,7 +24,8 @@ class Concierge def initialize(room_count) Lodging.create_rooms(room_count) #creating rooms upon initialization - rooms = CSV.read('data/all_hotel_rooms.csv', headers: true, header_converters: :symbol).map do |room| + rooms = CSV.read('data/all_hotel_rooms.csv', headers: true, header_converters: :symbol).map do |room| #converting string headers to symbols for hash + room[:reserved_dates] = [] #converting string '[]' to empty array [] room.to_h end @rooms_info = rooms @@ -35,7 +39,7 @@ def new_reservation(check_in, check_out) #makes new reservation based on two dat raise ArgumentError if Date.parse(check_out) < Date.parse(check_in) #checkout cannot be earlier than check in - book_this = Lodging.room_status(@rooms_info) #returns one availalbe room + book_this = Lodging.room_status(@rooms_info, check_in) #returns one available room reserved_dates = Lodging.create_date_range(check_in, check_out) #parses range for date, into array @@ -44,10 +48,41 @@ def new_reservation(check_in, check_out) #makes new reservation based on two dat end #finds room to be reserved update_room[:status] = "unavailable" #changes status of said room in the array of hashes as 'unavailable' - update_room[:reserved_dates] = reserved_dates + update_room[:reserved_dates] += reserved_dates #all reserved dates are added under previous dates + end + + def new_block(check_in, check_out, block = 1, discount = 0.15) #makes new reservation based on two dates + + raise ArgumentError if Date.parse(check_out) < Date.parse(check_in) #checkout cannot be earlier than check in + + reserved_dates = Lodging.create_date_range(check_in, check_out) #parses range for date, into array + block.times do + hold_this = Lodging.room_status(@rooms_info, check_in) #returns one available room + + update_room = @rooms_info.find do |room| + room[:room_number] == hold_this[:room_number] + end #finds room to be reserved + + new_cost = (update_room[:cost].to_f) - (update_room[:cost].to_f * discount) + + update_room[:cost] = new_cost.round(2).to_s + update_room[:status] = "hold" #changes status of said room in the array of hashes as 'unavailable' + update_room[:reserved_dates] += reserved_dates #all reserved dates are added under previous dates + end end - # + + def block_reserve(check_in, check_out) + block_dates = Lodging.create_date_range(check_in, check_out) #parses range for date, into array + held_room = @rooms_info.find do |room| + room[:status] == 'hold' && room[:reserved_dates] == block_dates + end #finds room to be reserved + + raise ArgumentError if held_room == nil + + held_room[:status] = 'unavailable' #changes status to unavailable aka reserved + end + def reserved_rooms(date) #see list of reserved rooms by date raise ArgumentError if !Date.parse(date).instance_of? Date @@ -58,13 +93,29 @@ def reserved_rooms(date) #see list of reserved rooms by date room if room[:reserved_dates] end - reserved_room_list = reserved_rooms.select do |room| - room if room[:reserved_dates].include? search_date + reserved_rooms.select! do |room| + room[:reserved_dates].include? search_date end - return reserved_room_list + return reserved_rooms + end + + def view_avail(date) + + raise ArgumentError if !Date.parse(date).instance_of? Date + + search_date = Date.parse(date) + + avail_rooms = @rooms_info.find_all do |room| + room if room[:status] == 'available' + end + + avail_rooms = @rooms_info.reject! do |room| + room[:reserved_dates].include? search_date + end + return avail_rooms end def receipt(room_number) #date step method to determine day count @@ -75,7 +126,7 @@ def receipt(room_number) #date step method to determine day count cost = check_out_room[:cost].to_f total_days = check_out_room[:reserved_dates].length - 1 - return (cost * total_days).round(2) + return Lodging.total_owed(total_days, cost) end diff --git a/lib/lodging.rb b/lib/lodging.rb index 96913a4ec..7d4dfbfd9 100644 --- a/lib/lodging.rb +++ b/lib/lodging.rb @@ -12,13 +12,9 @@ def self.create_rooms(room_count, cost = 200) #creates new rooms, assigns room n end end - def self.total_owed #totals cost of length of stay - puts "sup" - end - -def self.room_status(input) #check room_status +def self.room_status(input, check_in) #check room_status avail = input.find do |room| - room[:status] == "available" #returns first instance it finds of available room + room[:reserved_dates].last == Date.parse(check_in) || room[:status] == "available" #returns first instance it finds of available room end raise ArgumentError if avail == false @@ -26,8 +22,13 @@ def self.room_status(input) #check room_status return avail end +def self.total_owed(multiplier, price) #date step method to determine day count + total = multiplier.to_f * price.to_f + return total.round(2) +end + def self.create_date_range(date1, date2) - return (Date.parse(date1)..Date.parse(date2)).to_a + return (Date.parse(date1)..Date.parse(date2)).to_a end diff --git a/lib/room.rb b/lib/room.rb index b01507fef..8066969f5 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -15,7 +15,7 @@ def initialize(room_number, cost = 200) @cost = cost @status = :available - room = [@room_number, @cost, @status, nil, nil] + room = [@room_number, @cost, @status, Array.new] CSV.open('data/all_hotel_rooms.csv', 'a+') do |row| row << room @@ -24,7 +24,7 @@ def initialize(room_number, cost = 200) def self.available_room #to return one room with status available CSV.open('data/all_hotel_rooms.csv', 'r', headers: true) do |row| - return row + return row end end diff --git a/refactors.txt b/refactors.txt new file mode 100644 index 000000000..c52cf7652 --- /dev/null +++ b/refactors.txt @@ -0,0 +1 @@ +I would refactor mostly the concierge class. It is bigger than I want. I wanted it to be more of an 'viewing' sort of class but it ends up being more of an 'action' class. diff --git a/spec/concierge_spec.rb b/spec/concierge_spec.rb index e5f1032fb..2893a5ed4 100644 --- a/spec/concierge_spec.rb +++ b/spec/concierge_spec.rb @@ -4,7 +4,7 @@ #reset CSV data before(:each) do CSV.open('data/all_hotel_rooms.csv', 'w', headers: true) do |csv| - csv << ['room_number','cost','status','check_in','check_out'] + csv << ['room_number','cost','status', 'reserved_dates'] end CSV.open('data/reservations.csv', 'w', headers: true) do |csv| @@ -47,6 +47,18 @@ expect{concierge.new_reservation('August 7, 2019', 'August 28, 2018')}.must_raise ArgumentError end + it 'can reserve room on last day of previous res' do + tiny_hotel = Lodging::Concierge.new(1) + + + tiny_hotel.new_reservation('Sept 9, 2018', 'Sept 12, 2018') + tiny_hotel.new_reservation('Sept 12, 2018', 'Sept 14, 2018') + tiny_hotel.all_rooms + + expect(tiny_hotel.all_rooms[0][:reserved_dates].length).must_equal 7 + + end + end describe 'reserved rooms method' do @@ -77,10 +89,80 @@ end + describe 'new_block' do + before do + concierge.new_block('Dec 1, 2018', 'Dec 15, 2018', 5) + end + + it 'creates multiple holds for several rooms' do + + + first = concierge.all_rooms.first + fifth = concierge.all_rooms[4] + last = concierge.all_rooms.last + + expect(first[:status]).must_equal 'hold' + expect(fifth[:status]).must_equal 'hold' + expect(last[:status]).must_equal 'available' + + + end + + it 'updates pricing of each room to discounted rate' do + first = concierge.all_rooms.first + fifth = concierge.all_rooms[4] + last = concierge.all_rooms.last + + expect(first[:cost]).must_equal '170.0' + expect(fifth[:cost]).must_equal '170.0' + expect(last[:cost]).must_equal '200' + + end + + end + + describe 'block_reserve' do + before do + concierge.new_block('Dec 1, 2018', 'Dec 15, 2018', 5) + end + + it 'reserves from hotel block' do + concierge.block_reserve('Dec 1, 2018', 'Dec 15, 2018') + + reserved = concierge.all_rooms[0] + + expect(reserved[:status]).must_equal 'unavailable' + end + + it 'raises ArgumentError for different block dates' do + expect{concierge.block_reserve('Dec 12, 2018', 'Dec 15, 2018')}.must_raise ArgumentError + end + end + + + describe 'view avail method' do + it 'returns list of available rooms for date specified' do + concierge.new_reservation('Sept 9, 2018', 'Sept 12, 2018') #room 1 + concierge.new_reservation('Sept 13, 2018', 'Sept 20, 2018') #room 2 + concierge.new_reservation('Sept 10, 2018', 'Sept 20, 2018') #room 3 + concierge.new_reservation('Sept 6, 2018', 'Sept 13, 2018') #room 4 + + sept_12 = concierge.view_avail('Sept 12, 2018') + + expect(sept_12.length).must_equal 7 + expect(sept_12.first[:room_number]).must_equal '2' + expect(sept_12.first[:status]).must_equal 'unavailable' #unavailable starting 13/09 + expect(sept_12.last[:room_number]).must_equal '10' + + + end + + end + describe 'receipt' do it 'calculates total cost for stay' do concierge.new_reservation('Sept 9, 2018', 'Sept 12, 2018') #room 1 - + concierge.receipt(1) end end diff --git a/spec/lodging_spec.rb b/spec/lodging_spec.rb index 0df6d12bb..a1c766853 100644 --- a/spec/lodging_spec.rb +++ b/spec/lodging_spec.rb @@ -1,35 +1 @@ -# require_relative 'spec_helper' -# -# describe 'Lodging module methods' do -# -# describe 'create rooms' do -# -# let(:concierge) { -# Lodging::Concierge.new(10) -# } ##uses the create_rooms method -# -# it 'creates mulitiple instances of room' do -# concierge -# -# expect(Lodging::Room.show_list).must_be_instance_of Array -# expect(Lodging::Room.show_list.any? Lodging::Room).must_equal true -# -# expect(concierge.all_rooms.length).must_equal 10 -# end -# -# it 'assigns different room numbers to each instance up to x times' do -# Lodging.create_rooms(10) -# first = Lodging::Room.show_list.first -# last = Lodging::Room.show_list.last -# -# expect(Lodging::Room.show_list.length).must_equal 10 -# expect(first.room_number).must_equal 1 -# expect(last.room_number).must_equal 10 -# end -# -# it 'errors if argument passed is not integer' do -# expect{Lodging.create_rooms('forty')}.must_raise ArgumentError -# expect{Lodging.create_rooms(3.5)}.must_raise ArgumentError -# end -# end -# end +#ALL LODGING METHODS TESTED IN CLASS SPECS diff --git a/spec/room_spec.rb b/spec/room_spec.rb index df162107e..ad7ee47bc 100644 --- a/spec/room_spec.rb +++ b/spec/room_spec.rb @@ -4,7 +4,7 @@ #to clear CSV file before each test before(:each) do CSV.open('data/all_hotel_rooms.csv', 'w', headers: true) do |csv| - csv << ['room_number','cost','status'] + csv << ['room_number','cost','status', 'reserved_dates'] end CSV.open('data/reservations.csv', 'w', headers: true) do |csv| @@ -33,14 +33,11 @@ end describe 'available room' do - # let(:new_room) { - # CSV.read('all_hotel_rooms.csv', headers: true) - # } - it 'returns CSV row of available room' do + it 'returns CSV of available room' do Lodging.create_rooms(5) - expect(Lodging::Room.available_room).must_be_instance_of CSV::Row + expect(Lodging::Room.available_room).must_be_instance_of CSV end end From 2a0ac2b4541fde4b33c71f86a3ea460ccdc289c5 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Mon, 10 Sep 2018 07:27:32 -0700 Subject: [PATCH 12/18] refactors.txt --- refactors.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/refactors.txt b/refactors.txt index c52cf7652..421a29913 100644 --- a/refactors.txt +++ b/refactors.txt @@ -1 +1,5 @@ -I would refactor mostly the concierge class. It is bigger than I want. I wanted it to be more of an 'viewing' sort of class but it ends up being more of an 'action' class. +I would refactor mostly the concierge class. It is bigger than I want. I wanted it to be more of an 'viewing' sort of class but it ends up being more of an 'action' class. I want to move a lot of methods out from there. + +I tried to use CSV for my data, but none of the data was appending to my reservations file. I think if that worked, my concierge class would have been more the way I wanted it to be. It would rely more on the module methods than its own methods. + +I want to move around a lot of stuff and make it much more organized. From 05bfb45f6f7c5c43a1395aaeeeb9e8b029e9b776 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Sun, 30 Sep 2018 15:43:39 -0700 Subject: [PATCH 13/18] design activity md file added --- design-activity.md | 93 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 design-activity.md diff --git a/design-activity.md b/design-activity.md new file mode 100644 index 000000000..b46204778 --- /dev/null +++ b/design-activity.md @@ -0,0 +1,93 @@ +Activity: Evaluating Responsibility +As an example, here are two different implementations of a system to keep track of orders in an online shopping cart. + +Implementation A +class CartEntry + attr_accessor :unit_price, :quantity + def initialize(unit_price, quantity) + @unit_price = unit_price + @quantity = quantity + end +end + +class ShoppingCart + attr_accessor :entries + def initialize + @entries = [] + end +end + +class Order + SALES_TAX = 0.07 + def initialize + @cart = ShoppingCart.new + end + + def total_price + sum = 0 + @cart.entries.each do |entry| + sum += entry.unit_price * entry.quantity + end + return sum + sum * SALES_TAX + end +end +Implementation B +class CartEntry + def initialize(unit_price, quantity) + @unit_price = unit_price + @quantity = quantity + end + + def price + return @unit_price * @quantity + end +end + +class ShoppingCart + def initialize + @entries = [] + end + + def price + sum = 0 + @entries.each do |entry| + sum += entry.price + end + return sum + end +end + +class Order + SALES_TAX = 0.07 + def initialize + @cart = ShoppingCart.new + end + + def total_price + subtotal = @cart.price + return subtotal + subtotal * SALES_TAX + end +end +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 = for implementation A, the Order creates a new instance of ShoppingCart upon initialization. + + + + +How do the classes relate to each other? It might be helpful to draw a diagram on a whiteboard or piece of paper. +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? +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? +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? +Bonus question once you've read Metz ch. 3: Which implementation is more loosely coupled? +Once you've responded to the prompts, git add design-activity.md and git commit! From 82e7f9f940ae4cac206658e13c921c23637987be Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Sun, 30 Sep 2018 16:29:19 -0700 Subject: [PATCH 14/18] prompts done --- design-activity.md | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/design-activity.md b/design-activity.md index b46204778..32b14f88d 100644 --- a/design-activity.md +++ b/design-activity.md @@ -76,18 +76,34 @@ 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 = for implementation A, the Order creates a new instance of ShoppingCart upon initialization. + 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. -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? + 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? + + 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! From 0fac536ffa29d6aea99f0512e5a6a5339f5d59d0 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Mon, 1 Oct 2018 10:29:42 -0700 Subject: [PATCH 15/18] clearer md --- design-activity.md | 40 +++++++++++++++++++++++++++++++++------- lib/concierge.rb | 1 + 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/design-activity.md b/design-activity.md index 32b14f88d..d4d55656a 100644 --- a/design-activity.md +++ b/design-activity.md @@ -71,7 +71,7 @@ end 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? +## 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. @@ -81,29 +81,55 @@ Write down a sentence to describe each class. -How do the classes relate to each other? It might be helpful to draw a diagram on a whiteboard or piece of paper. +## 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? +## 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: +## 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. + 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? +## 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? +## 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? +Activity + +## 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. + + + +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. diff --git a/lib/concierge.rb b/lib/concierge.rb index 125a39c44..422986e6b 100644 --- a/lib/concierge.rb +++ b/lib/concierge.rb @@ -69,6 +69,7 @@ def new_block(check_in, check_out, block = 1, discount = 0.15) #makes new reserv update_room[:cost] = new_cost.round(2).to_s update_room[:status] = "hold" #changes status of said room in the array of hashes as 'unavailable' update_room[:reserved_dates] += reserved_dates #all reserved dates are added under previous dates + ap update_room end end From 1f99ebc3c18c30620feb60997139879990ed0036 Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Mon, 1 Oct 2018 10:34:16 -0700 Subject: [PATCH 16/18] fixed --- design-activity.md | 93 +++++++--------------------------------------- 1 file changed, 13 insertions(+), 80 deletions(-) diff --git a/design-activity.md b/design-activity.md index d4d55656a..8f9ccef38 100644 --- a/design-activity.md +++ b/design-activity.md @@ -1,77 +1,9 @@ -Activity: Evaluating Responsibility -As an example, here are two different implementations of a system to keep track of orders in an online shopping cart. - -Implementation A -class CartEntry - attr_accessor :unit_price, :quantity - def initialize(unit_price, quantity) - @unit_price = unit_price - @quantity = quantity - end -end - -class ShoppingCart - attr_accessor :entries - def initialize - @entries = [] - end -end - -class Order - SALES_TAX = 0.07 - def initialize - @cart = ShoppingCart.new - end - - def total_price - sum = 0 - @cart.entries.each do |entry| - sum += entry.unit_price * entry.quantity - end - return sum + sum * SALES_TAX - end -end -Implementation B -class CartEntry - def initialize(unit_price, quantity) - @unit_price = unit_price - @quantity = quantity - end - - def price - return @unit_price * @quantity - end -end - -class ShoppingCart - def initialize - @entries = [] - end - - def price - sum = 0 - @entries.each do |entry| - sum += entry.price - end - return sum - end -end - -class Order - SALES_TAX = 0.07 - def initialize - @cart = ShoppingCart.new - end - - def total_price - subtotal = @cart.price - return subtotal + subtotal * SALES_TAX - end -end -Prompts +# 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? +### 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. @@ -81,34 +13,35 @@ Write down a sentence to describe each class. -## How do the classes relate to each other? It might be helpful to draw a diagram on a whiteboard or piece of paper. +### 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? +### 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: +### 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? +### 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? +### 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: @@ -122,10 +55,10 @@ You might recall writing a file called refactor.txt. Take a look at the refactor 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? -Activity +**** + +### 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. -## 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. - If you need inspiration, remember that the reference implementation exists. From 8062098491ee2910db8162c557cdb87e49ce620e Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Mon, 1 Oct 2018 10:39:36 -0700 Subject: [PATCH 17/18] removed some unneccessary csv stuff --- design-activity.md | 2 +- lib/room.rb | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/design-activity.md b/design-activity.md index 8f9ccef38..9d5313baf 100644 --- a/design-activity.md +++ b/design-activity.md @@ -58,7 +58,7 @@ Do you still agree with your previous assesment, or could your refactor be furth **** ### 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. If you need inspiration, remember that the reference implementation exists. diff --git a/lib/room.rb b/lib/room.rb index 8066969f5..2e47266d2 100644 --- a/lib/room.rb +++ b/lib/room.rb @@ -22,11 +22,5 @@ def initialize(room_number, cost = 200) end end - def self.available_room #to return one room with status available - CSV.open('data/all_hotel_rooms.csv', 'r', headers: true) do |row| - return row - end - end - end end From b4769f7fe896f45fb491b9242cbac0f4a02ced4e Mon Sep 17 00:00:00 2001 From: Leanne Rivera Date: Mon, 1 Oct 2018 22:50:47 -0700 Subject: [PATCH 18/18] module methods removed --- design-activity.md | 2 +- lib/concierge.rb | 46 ++++++++++++++++++++++++++++++++++++++-------- lib/lodging.rb | 30 ------------------------------ 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/design-activity.md b/design-activity.md index 9d5313baf..e9b3d7853 100644 --- a/design-activity.md +++ b/design-activity.md @@ -58,7 +58,7 @@ Do you still agree with your previous assesment, or could your refactor be furth **** ### 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. + 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. diff --git a/lib/concierge.rb b/lib/concierge.rb index 422986e6b..ae15fec48 100644 --- a/lib/concierge.rb +++ b/lib/concierge.rb @@ -3,7 +3,6 @@ require 'csv' require 'pry' -require_relative 'lodging' require_relative 'room' #concierge can ACCESS list of all rooms in hotel = yes #concierge can RESERVE reservation for date range = yes @@ -22,7 +21,7 @@ class Concierge attr_accessor :rooms_info def initialize(room_count) - Lodging.create_rooms(room_count) #creating rooms upon initialization + Concierge.create_rooms(room_count) #creating rooms upon initialization rooms = CSV.read('data/all_hotel_rooms.csv', headers: true, header_converters: :symbol).map do |room| #converting string headers to symbols for hash room[:reserved_dates] = [] #converting string '[]' to empty array [] @@ -39,9 +38,9 @@ def new_reservation(check_in, check_out) #makes new reservation based on two dat raise ArgumentError if Date.parse(check_out) < Date.parse(check_in) #checkout cannot be earlier than check in - book_this = Lodging.room_status(@rooms_info, check_in) #returns one available room + book_this = Concierge.available_room(@rooms_info, check_in) #returns one available room - reserved_dates = Lodging.create_date_range(check_in, check_out) #parses range for date, into array + reserved_dates = Concierge.create_date_range(check_in, check_out) #parses range for date, into array update_room = @rooms_info.find do |room| room[:room_number] == book_this[:room_number] @@ -55,10 +54,10 @@ def new_block(check_in, check_out, block = 1, discount = 0.15) #makes new reserv raise ArgumentError if Date.parse(check_out) < Date.parse(check_in) #checkout cannot be earlier than check in - reserved_dates = Lodging.create_date_range(check_in, check_out) #parses range for date, into array + reserved_dates = Concierge.create_date_range(check_in, check_out) #parses range for date, into array block.times do - hold_this = Lodging.room_status(@rooms_info, check_in) #returns one available room + hold_this = Concierge.available_room(@rooms_info, check_in) #returns one available room update_room = @rooms_info.find do |room| room[:room_number] == hold_this[:room_number] @@ -74,7 +73,7 @@ def new_block(check_in, check_out, block = 1, discount = 0.15) #makes new reserv end def block_reserve(check_in, check_out) - block_dates = Lodging.create_date_range(check_in, check_out) #parses range for date, into array + block_dates = Concierge.create_date_range(check_in, check_out) #parses range for date, into array held_room = @rooms_info.find do |room| room[:status] == 'hold' && room[:reserved_dates] == block_dates end #finds room to be reserved @@ -127,10 +126,41 @@ def receipt(room_number) #date step method to determine day count cost = check_out_room[:cost].to_f total_days = check_out_room[:reserved_dates].length - 1 - return Lodging.total_owed(total_days, cost) + return Concierge.total_owed(total_days, cost) end + #creates multiple rooms at once, and assigns room number + def self.create_rooms(room_count, cost = 200) #creates new rooms, assigns room no. + raise ArgumentError if !room_count.is_a? Integer + i = 1 + room_count.times do + Room.new(i, cost) + i += 1 + end + end + + def self.available_room(input, check_in) #check room_status + avail = input.find do |room| + room[:reserved_dates].last == Date.parse(check_in) || room[:status] == "available" #returns first instance it finds of available room + end + + raise ArgumentError if avail == false + + return avail + end + + def self.total_owed(multiplier, price) #date step method to determine day count + total = multiplier.to_f * price.to_f + return total.round(2) + end + + def self.create_date_range(date1, date2) + return (Date.parse(date1)..Date.parse(date2)).to_a + end + + + end end end diff --git a/lib/lodging.rb b/lib/lodging.rb index 7d4dfbfd9..2662f1d7b 100644 --- a/lib/lodging.rb +++ b/lib/lodging.rb @@ -2,34 +2,4 @@ module Lodging - #creates multiple rooms at once, and assigns room number - def self.create_rooms(room_count, cost = 200) #creates new rooms, assigns room no. - raise ArgumentError if !room_count.is_a? Integer - i = 1 - room_count.times do - Room.new(i, cost) - i += 1 - end - end - -def self.room_status(input, check_in) #check room_status - avail = input.find do |room| - room[:reserved_dates].last == Date.parse(check_in) || room[:status] == "available" #returns first instance it finds of available room - end - - raise ArgumentError if avail == false - - return avail -end - -def self.total_owed(multiplier, price) #date step method to determine day count - total = multiplier.to_f * price.to_f - return total.round(2) -end - -def self.create_date_range(date1, date2) - return (Date.parse(date1)..Date.parse(date2)).to_a -end - - end