For this assignment, you will be working with a Magazine domain.
We have three models: Author
, Article
, and Magazine
.
For our purposes, an Author
has many Article
s, a Magazine
has many Article
s, and Article
s belong to both Author
and Magazine
.
Author
- Magazine
is a many to many relationship.
Note: You should draw your domain on paper or on a whiteboard before you start coding. Remember to identify a single source of truth for your data.
To get started, run bundle install
while inside of this directory.
Build out all of the methods listed in the deliverables. The methods are listed in a suggested order, but you can feel free to tackle the ones you think are easiest. Be careful: some of the later methods rely on earlier ones.
Remember! This code challenge does not have tests. You cannot run rspec
and you cannot run learn
. You’ll need to create your own sample instances so that you can try out your code on your own. Make sure your associations and methods work in the console before submitting.
We’ve provided you with a tool that you can use to test your code. To use it, run ruby tools/console.rb
from the command line. This will start a pry
session with your classes defined. You can test out the methods that you write here. You can add code to the tools/console.rb
file to define variables and create sample instances of your objects.
Writing error-free code is more important than completing all of the deliverables listed - prioritize writing methods that work over writing more methods that don’t work. You should test your code in the console as you write.
Similarly, messy code that works is better than clean code that doesn’t. First, prioritize getting things working. Then, if there is time at the end, refactor your code to adhere to best practices. Examples of best practices might be to use higher-level array methods such as map
, select
, and find
when appropriate in place of each
, or, when you encounter duplicated logic, to extract it into a shared helper method.
Before you submit! Save and run your code to verify that it works as you expect. If you have any methods that are not working yet, feel free to leave comments describing your progress.
Write the following methods in the classes in the files provided. Feel free to build out any helper methods if needed.
Deliverables use the notation #
for instance methods, and .
for class methods.
Some of the methods listed are provided to you in the starter code. You should check that they work correctly, and that you understand them.
Author#initialize(name)
Author#name
Magazine#initialize(name, category)
Magazine#name
Magazine#category
Magazine.all
Article#initialize(author, magazine, title)
Article#title
Article.all
Article#author
Article#magazine
Author#articles
Author#magazines
Magazine#contributors
Author#add_article(magazine, title)
Author#topic_areas
Magazine.find_by_name(name)
Magazine#article_titles
Magazine#contributing_authors
You can find the rubric for this assessment here.