-
Notifications
You must be signed in to change notification settings - Fork 25
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
Panda & Tiger level complete #10
Open
ralphos
wants to merge
11
commits into
RubyoffRails:master
Choose a base branch
from
ralphos:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1c8dd93
code does not blow up when searching for non-existent movie
ralphos dc199f3
tests for context in which movie is not found
ralphos be75f3f
displays a user's search history at the end of a session
ralphos 2523c29
reworded the question and now displays an average movie rating
ralphos ba6ae06
Refactored user_spec
ralphos eee909a
displays the average year for the movies a user has liked
ralphos 07b22d4
clarified spec wording
ralphos 498c803
can now calculate user's average movie rating per year'
ralphos 5a41527
Calculates slope and picking ability and refactored spec
ralphos 10f261d
Added a more explicit if/else statement if no movie is returned
ralphos 5f254b3
Removed unneccesary line
ralphos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class User | ||
attr_reader :name, :searches | ||
|
||
def initialize(name) | ||
@name = name | ||
@searches = [] | ||
end | ||
|
||
def add_to_searches(movie) | ||
@searches << movie | ||
end | ||
|
||
def rating | ||
movie_scores = searches.map { |movie| movie.score } | ||
movie_scores.inject { |sum, el| sum + el } / searches.size | ||
end | ||
|
||
def average_year | ||
movie_years = searches.map { |movie| movie.year } | ||
movie_years.inject { |sum, el| sum + el } / searches.size | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"total":0,"movies":[],"links":{"self":"http://api.rottentomatoes.com/api/public/v1.0/movies.json?q=top+tomatoes&page_limit=1&page=1"},"link_template":"http://api.rottentomatoes.com/api/public/v1.0/movies.json?q={search-term}&page_limit={results-per-page}&page={page-number}"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require_relative "../lib/user" | ||
require_relative "../lib/movie" | ||
describe User do | ||
|
||
let(:user) { User.new("Ralph") } | ||
let(:movie) { Movie.new(id: "1", title: "Some movie", year: 1985, score: 80) } | ||
let(:another_movie) { Movie.new(id: "2", title: "Another movie", year: 2000, score: 60) } | ||
|
||
context "when user is initialized" do | ||
|
||
it "has a name" do | ||
expect(user.name).to eq("Ralph") | ||
end | ||
|
||
it "has an empty list of movie searches" do | ||
expect(user.searches).to eq([]) | ||
end | ||
|
||
it "can calculate an average movie rating score" do | ||
user.add_to_searches(movie) | ||
user.add_to_searches(another_movie) | ||
expect(user.rating).to eq(70) | ||
end | ||
|
||
it "can calculate the average year of movies liked" do | ||
user.add_to_searches(movie) | ||
user.add_to_searches(another_movie) | ||
expect(user.average_year).to eq(1992) | ||
end | ||
end | ||
|
||
context "when a searching" do | ||
|
||
it "records a user's search" do | ||
user.add_to_searches(movie) | ||
expect(user.searches.first).to eq(movie) | ||
end | ||
|
||
it "records multiple searches" do | ||
user.add_to_searches(movie) | ||
user.add_to_searches(another_movie) | ||
expect(user.searches).to eq([movie, another_movie]) | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather you be more explicit about catching that there were no movies returned. Here you are returning nil if there was any exception.