diff --git a/lib/exhibit.rb b/lib/exhibit.rb index e69de29..2608490 100644 --- a/lib/exhibit.rb +++ b/lib/exhibit.rb @@ -0,0 +1,7 @@ +class Exhibit + attr_reader :name, :cost + def initialize(exhibit_information) + @name = exhibit_information[:name] + @cost = exhibit_information[:cost] + end +end \ No newline at end of file diff --git a/lib/museum.rb b/lib/museum.rb index e69de29..19c88cf 100644 --- a/lib/museum.rb +++ b/lib/museum.rb @@ -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 + diff --git a/lib/patron.rb b/lib/patron.rb index e69de29..3ba1a3d 100644 --- a/lib/patron.rb +++ b/lib/patron.rb @@ -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 \ No newline at end of file diff --git a/spec/exhibit_spec.rb b/spec/exhibit_spec.rb new file mode 100644 index 0000000..38c6bce --- /dev/null +++ b/spec/exhibit_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/museum_spec.rb b/spec/museum_spec.rb new file mode 100644 index 0000000..31aa5ec --- /dev/null +++ b/spec/museum_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/patron_spec.rb b/spec/patron_spec.rb new file mode 100644 index 0000000..941a835 --- /dev/null +++ b/spec/patron_spec.rb @@ -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 \ No newline at end of file