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

Matt Haefling #5

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(exhibit_info)
@name = exhibit_info[:name]
@cost = exhibit_info[:cost]
end
end
67 changes: 67 additions & 0 deletions lib/museum.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
class Museum
attr_reader :name,
:exhibits,
:patrons

def initialize(name)
@name = name
@exhibits = []
@recommend_exhibits = []
@patrons = []
@lottery_contestants = []
@winner = nil
end

def add_exhibit(exhibit_name)
@exhibits << exhibit_name
end

def recommend_exhibits(visitor)
@exhibits.select do |exhibit|
if visitor.interests.include?(exhibit.name)
@recommend_exhibits << exhibit
end
end
end

def admit(patron_entered)
@patrons << patron_entered
end

def patrons_by_exhibit_interest
pbei = {}
@exhibits.each do |exhibit|
patron = @patrons.select do |patron|
patron.interests.include?(exhibit.name)
end
pbei[exhibit] = patron
end
pbei
end

def ticket_lottery_contestants(interested_exhibit)
@lottery_exhibit = interested_exhibit
@exhibits.each do |exhibit|
@lottery_contestants = @patrons.select do |patron|
patron.spending_money < exhibit.cost
end
end
@lottery_contestants
end

def draw_lottery_winner
if @lottery_contestants.count > 0
@winner = @lottery_contestants.sample
else
@winner
end
end

def announce_lottery_winner
if @winner == nil
puts "No winners for this lottery"
else
puts"#{@winner.name} has won the #{@lottery_exhibit.name} exhibit lottery"
end
end
end
15 changes: 15 additions & 0 deletions lib/patron.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Patron
attr_reader :name,
:spending_money,
:interests

def initialize(name, money)
@name = name
@spending_money = money
@interests = []
end

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

RSpec.describe 'Exhibit' do
describe '#instantiate' do
it 'is an instance of Exhibit' do
exhibit = Exhibit.new({name: "Gems and Minerals", cost: 0})

expect(exhibit).to be_a(Exhibit)
end
end

describe '#initialize' do
it 'has a name and cost' do
exhibit = Exhibit.new({name: "Gems and Minerals", cost: 0})

expect(exhibit.name).to eq("Gems and Minerals")
expect(exhibit.cost).to eq(0)
end
end
end
173 changes: 173 additions & 0 deletions spec/museum_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
require './lib/museum'
require './lib/exhibit'
require './lib/patron'

RSpec.describe 'Museum' do
describe '#instantiate' do
it 'is a museum' do
dmns = Museum.new("Denver Museum of Nature and Science")

expect(dmns).to be_a(Museum)
end
end

describe '#initialize' do
it 'has a name, no exibits, and no addmitted patrons when initialized' do
dmns = Museum.new("Denver Museum of Nature and Science")

expect(dmns.name).to eq("Denver Museum of Nature and Science")
expect(dmns.exhibits).to eq([])
expect(dmns.patrons). to eq([])
end
end

describe '#add_exhibit' do
it 'can have different exhibits' 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})
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
end

describe '#recommend_exhibits' do
it 'recommends exhibits to patrons' 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})
dmns.add_exhibit(gems_and_minerals)
dmns.add_exhibit(dead_sea_scrolls)
dmns.add_exhibit(imax)
patron_1 = Patron.new("Bob", 20)
patron_1.add_interest("Dead Sea Scrolls")
patron_1.add_interest("Gems and Minerals")
patron_2 = Patron.new("Sally", 20)
patron_2.add_interest("IMAX")

expect(dmns.recommend_exhibits(patron_1)).to eq([gems_and_minerals, dead_sea_scrolls])
expect(dmns.recommend_exhibits(patron_2)).to eq([imax])
end
end

describe '#admit' do
it 'patrons are added as they get admited to the museum' do
dmns = Museum.new("Denver Museum of Nature and Science")
patron_1 = Patron.new("Bob", 0)
patron_2 = Patron.new("Sally", 20)
patron_3 = Patron.new("Johnny", 5)
expect(dmns.patrons).to eq([])
dmns.admit(patron_1)
dmns.admit(patron_2)
dmns.admit(patron_3)

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

describe '#patrons_by_exhibit_interest' do
it 'provides an array of patrons interested in each exhibit' 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})
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)

expect(dmns.patrons_by_exhibit_interest).to eq({gems_and_minerals => [patron_1], dead_sea_scrolls => [patron_1, patron_2, patron_3], imax => []})
end
end

describe '#ticket_lottery_contestants' do
it 'provides a list of patrons that are interested in an exhibit but cannot afford it' 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})
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)

expect(dmns.ticket_lottery_contestants(dead_sea_scrolls)).to eq([patron_1, patron_3])
end
end

describe '#draw_lottery_winner' do
it 'chooses a winner from the patrons that could not afford to see an exhibit' 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})
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)
dmns.ticket_lottery_contestants(dead_sea_scrolls)
dmns.draw_lottery_winner
# had just made the test to confirm the method was working.
end
end

describe '#announce_lottery_winner' do
it 'anounced who won the lottery ticket to the exhibit' 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})
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)
dmns.ticket_lottery_contestants(dead_sea_scrolls)
dmns.draw_lottery_winner
dmns.announce_lottery_winner
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
describe '#instantiate' do
it 'is an instance of Patron' do
patron_1 = Patron.new("Bob", 20)

expect(patron_1).to be_a(Patron)
end
end

describe '#initialize' do
it 'has a name and money' do
patron_1 = Patron.new("Bob", 20)

expect(patron_1.name).to eq("Bob")
expect(patron_1.spending_money).to eq(20)
end
end

describe '#add_interest' do
it 'starts with no interests' do
patron_1 = Patron.new("Bob", 20)

expect(patron_1.interests).to eq([])
end

it 'is able to add interests' do
patron_1 = Patron.new("Bob", 20)
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