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

Qory Week 4 Independent Challenge #14

Open
wants to merge 8 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
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--require spec_helper
--format documentation
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Gemfile

source "https://rubygems.org"

gem "pry" # Helpful for debugging and inspecting code
gem "rspec" # For writing and running tests
32 changes: 32 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
GEM
remote: https://rubygems.org/
specs:
coderay (1.1.3)
diff-lcs (1.5.1)
method_source (1.1.0)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.2)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)

PLATFORMS
arm64-darwin-24

DEPENDENCIES
pry
rspec

BUNDLED WITH
2.4.10
71 changes: 71 additions & 0 deletions Iteration_1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Iteration 1: Exhibit and Patron Classes

**Objectives:**
- Develop Exhibit and Patron classes using TDD to match the provided interaction pattern.
- **Exhibit Class:** Should initialize with a name and cost.
- **Patron Class:** Requires attributes for name, spending_money, and an empty array for interests. Implement an add_interest method for patrons.

## Error:
``` ruby
hani-sagal@Mac museum_2410 % rspec spec/exhibit_spec.rb

An error occurred while loading ./spec/exhibit_spec.rb.
Failure/Error:
RSpec.describe Exhibit do
it 'exists and has attributes' do
# Create a new Exhibit instance with a name and a cost
exhibit = Exhibit.new({name: "Gems and Minerals", cost: 0})

# Check that the exhibit is an instance of the Exhibit class
expect(exhibit).to be_a(Exhibit)

# Check that the exhibit has a name attribute set correctly
expect(exhibit.name).to eq("Gems and Minerals")

NameError:
uninitialized constant Exhibit
# ./spec/exhibit_spec.rb:5:in `<top (required)>'
No examples found.

Finished in 0.00002 seconds (files took 0.09977 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples
```

## Solution:
- I haven't bulit the ` exhibit` class yet.

## Error:
``` ruby
hani-sagal@Mac museum_2410 % rspec spec/patron_spec.rb

An error occurred while loading ./spec/patron_spec.rb.
Failure/Error:
RSpec.describe Patron do
it 'exists and has attributes' do
# Create a new Patron instance with a name and spending money
patron = Patron.new("Bob", 20)

# Check that the patron is an instance of the Patron class
expect(patron).to be_a(Patron)

# Check that the patron has a name attribute set correctly
expect(patron.name).to eq("Bob")

NameError:
uninitialized constant Patron
# ./spec/patron_spec.rb:5:in `<top (required)>'
No examples found.

Finished in 0.00002 seconds (files took 0.0996 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples
```
## Solution:
- - I haven't bulit the ` exhibit` class yet.


## Error:
``` ruby

```
## Solution:
- - I haven't bulit the ` exhibit` class yet.
114 changes: 114 additions & 0 deletions Iteration_2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Iteration 2: Museum Class with Recommendations

**Objectives:**
- Create the `Museum`class with the ability to add exhibits and recommend them based on patron interests.
- Implement `recommend_exhibits` to match exhibits with patron interests.

## Error:
``` ruby
hani-sagal@Mac museum_2410 % rspec spec/museum_spec.rb

While loading ./spec/museum_spec.rb a `raise SyntaxError` occurred, RSpec will now quit.
Failure/Error: __send__(method, file)

SyntaxError:
--> /Users/hani-sagal/turing_work/1mod/IC_challenges/Week_4_Challenge/museum_2410/spec/museum_spec.rb
Unmatched `(', missing `)' ?
5 Rspec.describe Museum do
30 it 'cam recommend exhibits based on patron interests' do
> 31 denvermns = Museum.new("Denver Museum of Nature and Science")
> 32 gems_and_minls = Exhibit.new({name: "Gems and Minerals", cost: 0})
> 33 dead_sea_scrolls = Exhibit.new({name: "Dead Sead Scrolls, cost: 10"})
> 34 cinemax = Exhibit.new({name: "Cinemax", cost: 15})
> 36 denvermns.add_exhibit(gems_and_minls)
> 37 denvermns.add_exhibit(dead_sea_scrolls)
> 38 denvermns.add_exhibit.(cinemax)
> 40 patron_1 = Patron.new("Scarlett", 20)
> 41 patron_1.add_interest("Dead Sea Scrolls")
> 42 patron_1.add_interest("Gems and Minerals")
> 44 patron_2 = Patron.new("Solaine", 20)
> 45 patron_2.add_interest("Cinemax")
> 47 expect(denvermns.recommend_exhibit(patron_1)).to eq([gems_and_minls, dead_sea_scrolls])
> 48 expect(denvermns.recommend_exhibit(patron_2). to eq([cinemax]
49 end
50 end/Users/hani-sagal/turing_work/1mod/IC_challenges/Week_4_Challenge/museum_2410/spec/museum_spec.rb:49: syntax error, unexpected `end', expecting ')' (SyntaxError)
end
^~~
# /Users/hani-sagal/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.13.2/lib/rspec/core/configuration.rb:2144:in `load'
# /Users/hani-sagal/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.13.2/lib/rspec/core/configuration.rb:2144:in `load_file_handling_errors'
# /Users/hani-sagal/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.13.2/lib/rspec/core/configuration.rb:1643:in `block in load_spec_files'
# /Users/hani-sagal/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.13.2/lib/rspec/core/configuration.rb:1641:in `each'
# /Users/hani-sagal/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.13.2/lib/rspec/core/configuration.rb:1641:in `load_spec_files'
# /Users/hani-sagal/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.13.2/lib/rspec/core/runner.rb:102:in `setup'
# /Users/hani-sagal/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.13.2/lib/rspec/core/runner.rb:86:in `run'
# /Users/hani-sagal/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.13.2/lib/rspec/core/runner.rb:71:in `run'
# /Users/hani-sagal/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.13.2/lib/rspec/core/runner.rb:45:in `invoke'
# /Users/hani-sagal/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.13.2/exe/rspec:4:in `<top (required)>'
# /Users/hani-sagal/.rbenv/versions/3.2.2/bin/rspec:25:in `load'
# /Users/hani-sagal/.rbenv/versions/3.2.2/bin/rspec:25:in `<main>'
#
# Showing full backtrace because every line was filtered out.
# See docs for RSpec::Configuration#backtrace_exclusion_patterns and
# RSpec::Configuration#backtrace_inclusion_patterns for more information.

Finished in 0.00011 seconds (files took 0.15357 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples

hani-sagal@Mac museum_2410 %
```

## Solution:
- As always, I syntax error ugh!!! I need to slow down.
1. **Missing Closing Braces:**
- In dead_sea_scrolls = Exhibit.new({name: "Dead Sea Scrolls, cost: 10"}), there’s a missing double-quote after "Dead Sea Scrolls".
2. **Extra Period:**
- In denvermns.add_exhibit.(cinemax), there’s an extra period after add_exhibit.
3. **Unclosed Parenthesis in Expectations:**
- In expect(denvermns.recommend_exhibit(patron_2).to eq([cinemax], I am missing a closing parenthesis and bracket for the expect statement.

## Error: Did not captialize spell RSpec correctly
``` ruby

An error occurred while loading ./spec/museum_spec.rb.
Failure/Error:
Rspec.describe Museum do
it 'exist and had attributes' do

denvermns = Museum.new("Denver Museum of Nature and Science")

expect(denvermns).to be_a(Museum)

expect(denvermns.name).to eq("Denver Museum of Nature and Science")

expect(denvermns.exhibit). to eq([])

NameError:
uninitialized constant Rspec
# ./spec/museum_spec.rb:5:in `<top (required)>'
No examples found.

Finished in 0.00002 seconds (files took 0.10173 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples

hani-sagal@Mac museum_2410 %
```

## Solution:
-


## Error:
``` ruby

```

## Solution:
-

## Error:
``` ruby

```

## Solution:
-
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## Instructions

* Fork this Repository
* Clone your forked repo to your computer.
* Fork this Repository
* Clone your forked repo to your computer.
* Complete the activity below.
* Push your solution to your forked repo
* Submit a pull request from your repository to this repository
Expand Down
12 changes: 12 additions & 0 deletions lib/exhibit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# lib/ exhibit.rb

class Exhibit

attr_reader :name, :cost
def initialize(details)

@name = details[:name]

@cost = details[:cost]
end
end
25 changes: 25 additions & 0 deletions lib/museum.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# lib/museum.rb

class Museum
# Provides access to the `name` and `exhibits` attributes
attr_reader :name, :exhibits

# Initializes the Museum with a name and an empty exhibits array
def initialize(name)
@name = name
@exhibits = []
end

# Adds an exhibit to the exhibits array
def add_exhibit(exhibit)
@exhibits << exhibit
end

# Recommends exhibits to a patron based on their interests
def recommend_exhibits(patron)
# Filters exhibits that match any of the patron's interests
@exhibits.select do |exhibit|
patron.interests.include?(exhibit.name)
end
end
end
17 changes: 17 additions & 0 deletions lib/patron.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# lib/ patron.rb

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
45 changes: 45 additions & 0 deletions project_outline.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Museum Project Outline

## 1. Overview and Goals

- My goal for this project is to create classes that model museum-related objects and behaviors, including visitors, exhibits, and patron interests.
- I’ll be implementing core classes such as `Museum`, `Exhibit`, and `Patron`, which will interact to reflect visitors' interests in specific exhibits within the museum.

## 2. Core Components and Class Overview

- **Patron**: Represents museum visitors, with attributes for each patron's name and interests.
- **Exhibit**: Models the exhibits available at the museum, with properties such as `name` and `cost`.
- **Museum**: Manages the museum's exhibits and interactions, handling tasks such as admitting patrons and managing revenue generated from exhibit admissions.

## 3. Project Requirements (TDD Approach)

- **Patron Tests**: I will develop test cases for `Patron` attributes (`name` and `interests`) and for behaviors related to adding interests.
- **Exhibit Tests**: I’ll write tests to ensure that exhibit properties, specifically `name` and `cost`, are accessible and correct.
- **Museum Tests**: I’ll write tests for `Museum` methods that manage adding patrons, processing payments, and listing exhibits based on visitor interests.

## 4. Suggested Flow

- I’ll begin with the `Exhibit` class and its tests, as this class is simpler and foundational to the museum structure.
- Next, I’ll move on to the `Patron` class to implement patron interests.
- Finally, I’ll build out the `Museum` class, which integrates both exhibits and patrons to complete the project.

## 5. Documentation and Code Comments

- I’ll use structured comments and annotations within the code, but I plan to hold off on detailed commenting until I have all functionality implemented.
- I’ll consider adding additional markdown files to document each class and test structure to provide clarity and organization.


Iteration 3: Exhibit Interests and Lottery

• Objectives:
• Extend the Museum class to handle:
• patrons_by_exhibit_interest: Returns a hash mapping exhibits to patrons interested in them.
• ticket_lottery_contestants: Identifies patrons with insufficient funds but interest in specific exhibits.
• draw_lottery_winner and announce_lottery_winner: Randomly select a lottery winner from contestants.

Iteration 4: Admission and Revenue Tracking

• Objectives:
• Update Museum so patrons can attend exhibits based on available funds and interests, prioritizing higher-cost exhibits.
• Track revenue and generate a patrons_of_exhibits hash showing which patrons attended each exhibit.
• Implement a revenue method to calculate the total collected from patron spending.
19 changes: 19 additions & 0 deletions spec/exhibit_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# spec/ exhibit_spec.rb

require './lib/exhibit' # Load the Exhibit class file

RSpec.describe Exhibit do
it 'exists and has attributes' do
# Create a new Exhibit instance with a name and a cost
exhibit = Exhibit.new({name: "Gems and Minerals", cost: 0})

# Check that the exhibit is an instance of the Exhibit class
expect(exhibit).to be_a(Exhibit)

# Check that the exhibit has a name attribute set correctly
expect(exhibit.name).to eq("Gems and Minerals")

# Check that the exhibit has a cost attribute set correctly
expect(exhibit.cost).to eq(0)
end
end
Loading