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

Katya Weicht #9

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/exhibit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Exhibit
attr_reader :name, :cost
def initialize(exhibit_information)
@name = exhibit_information[:name]
@cost = exhibit_information[:cost]
end
end
70 changes: 70 additions & 0 deletions lib/museum.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class Museum
attr_reader :name, :exhibits, :patrons
def initialize(name)
@name = name
@exhibits = []
@patrons = []

end

def add_exhibit(exhibit)
@exhibits << exhibit
end


def recommend_exhibits(patron)
recommended_exhibits = []

@exhibits.each do |exhibit| #iterate over exhibits first because it is a larger array than interests
patron.interests.map do |interest|
if interest == exhibit.name
recommended_exhibits << exhibit
end
end
end
return recommended_exhibits
end

# def recommend_exhibits(patron)
# result = []
# @exhibits.each do |exhibit|
# if patron.interests.include?(exhibit.name)
# result << exhibit
# end
# end
# result
# end

# def recommend_exhibits(patron)
# @exhibits.find_all do |exhibit|
# patron.interests.include?(exhibit.name)
# end
# end


def admit(patron)
@patrons << patron
#@patrons.push(patron) this does the same thing
end



def patrons_by_exhibit_interest #creates a hash
result = {}
@exhibits.each do |exhibit|
result[exhibit] = []
end
@patrons.each do |patrons|
recommend_exhibits(patrons).each do |exhibit|
binding.pry
result[exhibit] << patrons #at the key of recommended exhibit shovel in the patron to the array
end
end
result
end




end

12 changes: 12 additions & 0 deletions lib/patron.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Patron
attr_reader :name, :spending_money, :interests
def initialize(name,spending_money)
@name = name
@spending_money = spending_money
@interests = []
end

def add_interest(interest)
@interests << interest
end
end
22 changes: 22 additions & 0 deletions spec/exhibit_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require './lib/exhibit'

RSpec.describe Exhibit do
before (:each) do
@exhibit = Exhibit.new({name: "Gems and Minerals", cost: 0})
end
describe "#initialize" do
it 'exists' do
expect(@exhibit).to be_a(Exhibit)
expect(Exhibit).to respond_to(:new).with(1).argument
end
it 'has a name' do
expect(@exhibit.name).to eq("Gems and Minerals")
expect(Exhibit).to respond_to(:name).with(0).arguments
end

it 'has a cost' do
expect(@exhibit.cost).to eq(0)
end
end

end
132 changes: 132 additions & 0 deletions spec/museum_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
require './lib/museum'
require './lib/patron'
require './lib/exhibit'
require 'pry'

RSpec.describe Museum do
before(:each) do
@dmns = Museum.new("Denver Museum of Nature and Science")
@gems_and_minerals = Exhibit.new({name: "Gems and Minerals", cost: 0})
@dead_sea_scrolls = Exhibit.new({name: "Dead Sea Scrolls", cost: 10})
@imax = Exhibit.new({name: "IMAX",cost: 15})
end
describe "#initialize"
it 'exists' do
expect(@dmns).to be_a(Museum)
end
it 'has a name' do
expect(@dmns.name).to eq("Denver Museum of Nature and Science")
end
describe "exhibits" do
it 'has exhibits' do
expect(@dmns.exhibits).to eq([])
end
it 'can add exhibits' do

expect(@dmns.exhibits).to eq([])

@dmns.add_exhibit(@gems_and_minerals)
@dmns.add_exhibit(@dead_sea_scrolls)
@dmns.add_exhibit(@imax)

expect(@dmns.exhibits).to eq([@gems_and_minerals, @dead_sea_scrolls, @imax])

end
it 'can recommend exhibits' do
#add exhibits to the museum

@dmns.add_exhibit(@gems_and_minerals)
@dmns.add_exhibit(@dead_sea_scrolls)
@dmns.add_exhibit(@imax)

expect(@dmns.exhibits).to eq([@gems_and_minerals, @dead_sea_scrolls, @imax])

#create patron one and add interests

patron_1 = Patron.new("Bob", 20)

patron_1.add_interest("Dead Sea Scrolls")
patron_1.add_interest("Gems and Minerals")

#create patron two and add interests

patron_2 = Patron.new("Sally", 20)

patron_2.add_interest("IMAX")

#recommend exhibits to patron one

@dmns.recommend_exhibits(patron_1)
expect(@dmns.recommend_exhibits(patron_1)).to eq([@gems_and_minerals, @dead_sea_scrolls])

#recommend exhibits to patron two

@dmns.recommend_exhibits(patron_2)
expect(@dmns.recommend_exhibits(patron_2)).to eq([@imax])

end

end
describe "admittance" do
it 'can admit patrons' do

@dmns.add_exhibit(@gems_and_minerals)
@dmns.add_exhibit(@dead_sea_scrolls)
@dmns.add_exhibit(@imax)

expect(@dmns.patrons).to eq([])

patron_1 = Patron.new("Bob", 0)

patron_1.add_interest("Gems and Minerals")
patron_1.add_interest("Dead Sea Scrolls")

patron_2 = Patron.new("Sally", 20)

patron_2.add_interest("Dead Sea Scrolls")

patron_3 = Patron.new("Johnny", 5)

patron_3.add_interest("Dead Sea Scrolls")

@dmns.admit(patron_1)
@dmns.admit(patron_2)
@dmns.admit(patron_3)

expect(@dmns.patrons).to eq([patron_1,patron_2,patron_3])

end
it 'can sort patrons by exhibit interest' do
@dmns.add_exhibit(@gems_and_minerals)
@dmns.add_exhibit(@dead_sea_scrolls)
@dmns.add_exhibit(@imax)

patron_1 = Patron.new("Bob", 0)

patron_1.add_interest("Gems and Minerals")
patron_1.add_interest("Dead Sea Scrolls")

patron_2 = Patron.new("Sally", 20)

patron_2.add_interest("Dead Sea Scrolls")

patron_3 = Patron.new("Johnny", 5)

patron_3.add_interest("Dead Sea Scrolls")

@dmns.admit(patron_1)
@dmns.admit(patron_2)
@dmns.admit(patron_3)

expected_hash = {
@gems_and_minerals => [patron_1],
@dead_sea_scrolls => [patron_1,patron_2,patron_3],
@imax => []
}

expect(@dmns.patrons_by_exhibit_interest).to eq(expected_hash)

end

end
end
36 changes: 36 additions & 0 deletions spec/patron_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require './lib/patron'

RSpec.describe Patron do
before (:each) do
@patron_1 = Patron.new("Bob", 20)
end
describe "#initialize" do
it 'exists' do
expect(@patron_1).to be_a(Patron)
expect(Patron).to respond_to(:new).with(2).arguments
end
it 'has a name' do
expect(@patron_1.name).to eq("Bob")
end
it 'has spending money' do
expect(@patron_1.spending_money).to eq(20)
end
end
describe "#patron interests" do
it 'has interest' do
expect(@patron_1.interests).to eq([])
end
it 'can add interests' do
expect(@patron_1).to respond_to(:add_interest).with(1).argument
expect(@patron_1.interests).to eq([])

@patron_1.add_interest("Dead Sea Scrolls")

expect(@patron_1.interests).to eq(["Dead Sea Scrolls"])

@patron_1.add_interest("Gems and Minerals")

expect(@patron_1.interests).to eq(["Dead Sea Scrolls", "Gems and Minerals"])
end
end
end