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

Jackson Bickler Museum #11

Open
wants to merge 1 commit 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
9 changes: 9 additions & 0 deletions lib/exhibit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

class Exhibit
attr_reader :name, :cost

def initialize(info_hash)
@name = info_hash[:name]
@cost = info_hash[:cost]
end
end
36 changes: 36 additions & 0 deletions lib/museum.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'spec_helper'

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)
@exhibits.select do |exhibit|
patron.interests.include?(exhibit.name)
end
end

def admit(patron)
@patrons << patron
end

def patrons_by_exhibit_interest
patron_interests = {}
@exhibits.each do |exhibit|
museum_patrons = @patrons.select do |patron|
patron.interests.include?(exhibit.name)
end
patron_interests[exhibit] = museum_patrons
end
patron_interests
end
end
13 changes: 13 additions & 0 deletions lib/patron.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

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
14 changes: 14 additions & 0 deletions spec/exhibit_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'spec_helper'

RSpec.describe Exhibit do
before(:each) do
@exhibit_info = { name: "Gems and Minerals", cost: 0 }
@exhibit_1 = Exhibit.new(@exhibit_info)
end
describe "intitialize" do
it "exitis with info" do
expect(@exhibit_1.name).to eq("Gems and Minerals")
expect(@exhibit_1.cost).to eq(0)
end
end
end
70 changes: 70 additions & 0 deletions spec/museum_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
require "spec_helper"

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})
@patron_1 = Patron.new("Bob", 20)
@patron_2 = Patron.new("Sally", 20)
end

describe "intitalize" do
it "exitis with attrbibutes" do
expect(@dmns.name).to eq("Denver Museum of Nature and Science")
expect(@dmns.exhibits).to eq([])
end
end

describe "add_exhibit" do
it "adds exhibit to exhibits array" do
@dmns.add_exhibit(@gems_and_minerals)
@dmns.add_exhibit(@dead_sea_scrolls)
@dmns.add_exhibit(@imax)

expect(@dmns.exhibits).to be_an(Array)
expect(@dmns.exhibits[0]).to be_a_instance_of(Exhibit)
expect(@dmns.exhibits.length).to eq(3)
end
end

describe "recommend_exhibits" do
it "recommends exhibits to patrons based on interests" do
@dmns.add_exhibit(@gems_and_minerals)
@dmns.add_exhibit(@dead_sea_scrolls)
@dmns.add_exhibit(@imax)
@patron_1.add_interest("Dead Sea Scrolls")
@patron_1.add_interest("Gems and Minerals")
expect(@dmns.recommend_exhibits(@patron_1)).to be_an(Array)
expect(@dmns.recommend_exhibits(@patron_1)).to contain_exactly(@gems_and_minerals, @dead_sea_scrolls)
@patron_2.add_interest("IMAX")
expect(@dmns.recommend_exhibits(@patron_2)).to contain_exactly(@imax)
end
end

describe "admit" do
it "admits patrons into the museum" do
@dmns.admit(@patron_1)
@dmns.admit(@patron_2)
expect(@dmns.patrons).to eq([@patron_1, @patron_2])
end
end

describe "patrons_by_exhibit_interest" do
it "shows all patrons interets admitted to the museum" do
@dmns.add_exhibit(@gems_and_minerals)
@dmns.add_exhibit(@dead_sea_scrolls)
@dmns.add_exhibit(@imax)
@patron_1.add_interest("Dead Sea Scrolls")
@patron_1.add_interest("Gems and Minerals")
@patron_2.add_interest("IMAX")
@dmns.admit(@patron_1)
@dmns.admit(@patron_2)
expect(@dmns.patrons_by_exhibit_interest).to be_a(Hash)
expect(@dmns.patrons_by_exhibit_interest[@gems_and_minerals]).to include(@patron_1)
expect(@dmns.patrons_by_exhibit_interest[@imax]).to include(@patron_2)

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

RSpec.describe Patron do
before(:each) do
@patron_1 = Patron.new("bob", 20)
end
describe "intitlaize" do
it "exitis with attributes" do
expect(@patron_1.name).to eq("bob")
expect(@patron_1.spending_money).to eq(20)
expect(@patron_1.interests).to eq([])
end
end
describe "add_interest" do
it "adds interest to interests array" do
@patron_1.add_interest("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
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require "rspec"
require './lib/exhibit'
require './lib/patron'
require './lib/museum'