Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipes- Roxanne Agerone - Hotel #41

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
960124a
added rakefile (copied from Scrabble)
RAgerone Sep 5, 2017
90cf909
created room class and hotel module
RAgerone Sep 5, 2017
8023242
added spec_helper from Scrabble
RAgerone Sep 5, 2017
f84da5d
created specs for my files
RAgerone Sep 5, 2017
928572e
added reservation class into module with initialization
RAgerone Sep 5, 2017
711a988
added class Admin, outlined ideas for reserving, outlined methods: ro…
RAgerone Sep 5, 2017
0b330fe
added require relative to spec_helper
RAgerone Sep 5, 2017
6a6c20e
realized that room.rb would be a more fitting name than hotel.rb
RAgerone Sep 5, 2017
d533ac4
required relatives
RAgerone Sep 5, 2017
ea9d2a5
added required relatives
RAgerone Sep 5, 2017
2646785
created admin_spec
RAgerone Sep 5, 2017
42c1057
changed names of both of these files to room
RAgerone Sep 6, 2017
fba8769
added method to pull out date array
RAgerone Sep 6, 2017
f751a30
bones for room available method
RAgerone Sep 6, 2017
1280429
fixed wrong filepath in rake
RAgerone Sep 6, 2017
adefdcb
fixed dates checked
RAgerone Sep 6, 2017
7ff4860
fixed dates method
RAgerone Sep 6, 2017
26a295a
writing tests for init reservation and checking for dates
RAgerone Sep 6, 2017
9f7f553
added and subtracted minor things to ensure spec files work
RAgerone Sep 6, 2017
5271d68
figuring out mixins
RAgerone Sep 6, 2017
4661e96
fixed a bug in front of the class
RAgerone Sep 7, 2017
e183784
fixing bugs in rooms_available?
RAgerone Sep 7, 2017
9c8af3c
changing test code to fix bugs
RAgerone Sep 7, 2017
7fc0a56
fixing the glaring bugs that are slowly swallowing my soul
RAgerone Sep 7, 2017
6e7f729
trying to fix mixins, but not sure
RAgerone Sep 7, 2017
560cdda
minor changes
RAgerone Sep 7, 2017
3809c11
minor changes
RAgerone Sep 7, 2017
21fb811
minor changes
RAgerone Sep 7, 2017
01d12b2
added a feature to change the discount of blocks
RAgerone Sep 8, 2017
16717a2
commenting what I need to do
RAgerone Sep 8, 2017
b77d844
changing the default value of room to TBD
RAgerone Sep 8, 2017
1e42a69
changing test to accomodate changed code
RAgerone Sep 8, 2017
c7b07fc
I made the mixin work by myself! I was going to get help, but everyon…
RAgerone Sep 8, 2017
42dbba7
I'm writing blockable methods in admin which will later be moved to a…
RAgerone Sep 8, 2017
f9993a9
testing reserveable
RAgerone Sep 8, 2017
ce0956a
isoloating mixins
RAgerone Sep 8, 2017
58b5035
moved to reserveable_spec file
RAgerone Sep 8, 2017
426db6e
added multiple rooms feature to blocks and wrote tests accordingly
RAgerone Sep 8, 2017
d7a60e4
changed date format
RAgerone Sep 8, 2017
48e9820
changed format in tests
RAgerone Sep 8, 2017
01ad511
moved blockable to new module to be used as mixin, likewise new folde…
RAgerone Sep 8, 2017
7560253
teaking the code
RAgerone Sep 8, 2017
9161ef7
added feature to reservable to check for blocks
RAgerone Sep 11, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'rake/testtask'

Rake::TestTask.new do |t|
t.libs = ["lib"]
t.warning = true
t.test_files = FileList['specs/*_spec.rb']
end

task default: :test
36 changes: 36 additions & 0 deletions lib/admin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require_relative './concerns/dateable'
require_relative './concerns/reserveable'
require_relative './concerns/blockable'
require_relative 'reservation'
require 'date'
require 'securerandom'
require 'pry'
module Hotel


class Admin
include Hotel::Dateable::InstanceMethods
include Hotel::Reserveable::InstanceMethods
include Hotel::Blockable::InstanceMethods

attr_reader :reservations_list, :all_rooms, :block_list
# def get_date_range(check_in, check_out)
# return (check_in ... check_out).to_a
# end

def initialize
@reservations_list = []
@block_list = []
@all_rooms = []
make_hotel_rooms
end
#could possibly go back in here and use a rooms class
def make_hotel_rooms
(1..20).each do |num|
@all_rooms << num #Hotel::Room.new(num) I don't think I have to do this
end
end

end #class Admin

end
41 changes: 41 additions & 0 deletions lib/blocks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require_relative 'reservation'
require_relative './concerns/dateable'
require 'date'
require 'pry'
module Hotel


class Block < Reservation
include Hotel::Dateable::InstanceMethods


attr_accessor :date_range, :room, :name, :contact_info, :check_in, :check_out, :price, :discount, :num_rooms

def initialize(check_in, check_out, name, contact_info, discount, num_rooms)

super(check_in, check_out, room, name, contact_info)
@discount = discount
@price = (@date_range.length) * PRICE_PER_NIGHT * calculate_discount(@discount)
@num_rooms = num_rooms
end

def change_discount(discount)
@discount = calculate_discount(discount)
end

def price_all_rooms
@num_rooms * @price
end

def change_rooms_block(number)
@num_rooms = number
end

private


def calculate_discount(number)
(100 - number) * 0.01
end
end
end
62 changes: 62 additions & 0 deletions lib/concerns/blockable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module Hotel
module Blockable
module InstanceMethods
include Hotel::Dateable::InstanceMethods

def create_block(check_in, check_out, name, contact_info, discount, num_rooms)

available_rooms = rooms_available?(check_in, check_out)
num_rooms_in_range?(num_rooms, available_rooms)
#id_num = SecureRandom.uuid don't need it, but I like the idea

@block_list << Hotel::Block.new(check_in, check_out, name, contact_info, discount, num_rooms)

end


def convert_block_to_reservation(name)
being_converted = finder(name, :name, block_list)
@block_list = @block_list - being_converted
being_converted.each{ |block| block.num_rooms.times do |thing|
reserve(block.check_in, block.check_out, rooms_available?(block.check_in, block.check_out)[0], block.name, block.contact_info)
end
}
@block_list = @block_list - being_converted
end

def delete_block(name)
being_deleted = finder(name, :name, block_list)
# binding.pry
@block_list = @block_list - being_deleted
end

def find_block_name(name)
finder(name, :name, block_list)
end

def find_block_by_date(date)
finder(date, :date_range, block_list)

end

def number_rooms_blocked_by_date_range(check_in, check_out)
num_rooms = 0
date_range = get_date_range(check_in, check_out)
date_range.each do |date|
blocks_dates = @block_list.find_all{|block| (block.date_range & date_range).any?}
num_rooms = blocks_dates.sum{|block| block.num_rooms}
end
num_rooms
end

private
def num_rooms_in_range?(num, rooms_available)

raise ArgumentError.new("The number of rooms is out of range") if num > rooms_available.length

end


end #blockable
end #InstanceMethods
end #Hotel
13 changes: 13 additions & 0 deletions lib/concerns/dateable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Hotel
module Dateable
module InstanceMethods
def get_date_range(check_in, check_out)
(check_in ... check_out).to_a
end
#ability to do searchy things
def finder(search_term, instance_variable, search_group)
search_group.find_all{|element| element.send(instance_variable).include?(search_term)}
end
end
end
end
55 changes: 55 additions & 0 deletions lib/concerns/reserveable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
module Hotel
module Reserveable
module InstanceMethods
include Hotel::Dateable::InstanceMethods


def reserve(check_in, check_out, room, name, contact_info)
#checks that the date hash't been previously reserved, and there are enough rooms for the blocks

raise ArgumentError.new("This room is already reserved on these days") if rooms_available?(check_in, check_out).include?(room) == false
new_reservation = Hotel::Reservation.new(check_in, check_out, room, name, contact_info)

@reservations_list << new_reservation


end#reserve

def rooms_available?(check_in, check_out)
blocks_for_date = number_rooms_blocked_by_date_range(check_in, check_out)
wanted_dates = get_date_range(check_in, check_out)
reserved_rooms_for_dates = []

case
when @reservations_list == []
return @all_rooms
else
@reservations_list.each do |reservation|
#needs to check if the room is included in this reservation on the day

overlap = reservation.dates_reserved & wanted_dates
overlap.any? ? reserved_rooms_for_dates << reservation.room : false

end
end

available_rooms = @all_rooms - reserved_rooms_for_dates
if blocks_for_date >= available_rooms.length
raise ArgumentError.new("Blocks for this date prohibit us from reserving rooms")
else
available_rooms
end
end#rooms_available


def reservations_by_name(name_request)
finder( name_request, :name, reservations_list)

end#reservations_by_date

def reservations_by_date(date)
finder(date, :date_range, reservations_list )
end#reservations_by_date
end
end
end
38 changes: 38 additions & 0 deletions lib/reservation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# require_relative 'hotel'
require_relative './concerns/dateable'
require 'date'
require 'pry'

module Hotel
PRICE_PER_NIGHT = 200
#
# def get_date_range(check_in, check_out)
# return (Date.new(check_in[0], check_in[1], check_in[2]) ... Date.new(check_out[0], check_out[1], check_out[2])).to_a
# end

class Reservation
include Hotel::Dateable::InstanceMethods

attr_accessor :date_range, :room, :name, :contact_info, :check_in, :check_out, :price

def initialize(check_in, check_out, room, name, contact_info)
@check_in = check_in
@check_out = check_out
@date_range = populate_date_range(@check_in, @check_out)
@room = room
@name = name
@contact_info = contact_info
@price = (@date_range.length) * PRICE_PER_NIGHT
end

def populate_date_range(check_in, check_out)
get_date_range(check_in, check_out)
end

def dates_reserved
@date_range
end #end available?

end#end class
# binding.pry
end#end module
12 changes: 12 additions & 0 deletions lib/room.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Hotel

class Room

attr_reader :number
def initialize( name )
@number = number
end
end


end
17 changes: 17 additions & 0 deletions specs/admin_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require_relative '../lib/admin'
require_relative 'spec_helper'
require 'pry'

describe "class Admin" do

describe "initialize" do
it "initializes all instance variables" do
admin_1 = Hotel::Admin.new
admin_1.all_rooms.length.must_equal 20
admin_1.reservations_list.must_be_instance_of Array
admin_1.must_be_instance_of Hotel::Admin
admin_1.block_list.must_be_instance_of Array
end
end

end#end describe Admin
60 changes: 60 additions & 0 deletions specs/blockable_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
require_relative '../lib/concerns/blockable'
require_relative 'spec_helper'

describe "blockable" do
before do
@admin = Hotel::Admin.new
@admin.create_block(Date.new(2012, 07, 16), Date.new(2012, 07, 19), "Bill Murray", "Japan", 5, 14)
end
it "can create a block" do

@admin.block_list[0].must_be_instance_of Hotel::Block
end

it "won't take a room of blocks that is out of range" do
proc{@admin.create_block(Date.new(2012, 07, 16), Date.new(2012, 07, 19), "Bill Murray", "Japan", 5, 27)}.must_raise ArgumentError
end

it "pushes the block into the block_list" do
@admin.block_list.length.must_equal 1
end

it "can delete a block" do
@admin.delete_block("Bill Murray")
@admin.block_list.length.must_equal 0
end

it "can find a block from the block_list by name" do
@admin.create_block(Date.new(2012, 07, 20), Date.new(2012, 07, 24), "Bill Murray", "Japan", 5, 3)
this_block = @admin.find_block_name("Bill Murray")
this_block.each do |block|
block.must_be_instance_of Hotel::Block
end
this_block.length.must_equal 2
end

it "can find a block from the block_list by date" do
this_block = @admin.find_block_by_date(Date.new(2012, 7, 18))
this_block.each do |block|
block.must_be_instance_of Hotel::Block
end
this_block.length.must_equal 1
this_other_block = @admin.find_block_by_date(Date.new(2012, 7, 30), )
this_other_block.length.must_equal 0

end

it "can convert a block to a reservation by name" do

@admin.convert_block_to_reservation("Bill Murray")
@admin.rooms_available?(Date.new(2012, 7, 18), Date.new(2012, 7, 19)).length.must_equal 6
@admin.block_list.length.must_equal 0
end

it "can find a number of rooms blocked by date range" do
num_blocked = @admin.number_rooms_blocked_by_date_range(Date.new(2012, 07, 16), Date.new(2012, 07, 19))
num_blocked.must_equal 14

end

end#end blockable
Loading