Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save philsof/5fa5c2b146f894d6655a to your computer and use it in GitHub Desktop.
Save philsof/5fa5c2b146f894d6655a to your computer and use it in GitHub Desktop.
Code review for pair-kerryimai,yilu1021 branch: scraping-hn-1-building-objects-challenge

Your code works! Good job! Here are some notes:

  • Line 3 in your comment.rb file sets two attribute readers: attr_reader :comment_user_ID, :comment_text. These attribute names are redundant since they are attributes on your comment class. Removing the word 'comment' from the attribute names and simply naming them attr_reader :user_ID, :text would suffice.
  • Lines 12-14 in your post class can be refactored. Instead of this:
  def comments
    @collection_of_comments
  end

you could eliminate the need to write this method by naming your collection @comments and create an attr_reader for it: attr_reader :comments

  • Heads up: You have a display method in your post class that controls what it printed to the console. This does not belong in your post class code, but should rather be in your runner code. (Your runner.rb file is currently functioning as your controller. Soon you will learn the MVC pattern and will need to keep these functions separate.) Hint: In order to move your display code to your runner file, you would need to refactor your post class in order to access your post object from the runner. Another hint: utilize attr_reader on your post class as you did on your comment class.
  • To make your runner code much easier to read and follow (which is very important!), what if you created your comment objects first, then put them all into an array, then create your post object and pass the comments array to your Post.new as an argument. As in other words, have all of your comment creating code first, resulting in a comments array, then have all of your post creating code (with the comments array being one of the args passed to Post.new), then print the post to console. That would be much easier to follow.
  • Be sure to delete any unused code (at the end of your post.rb file, and one line in your runner.rb file)

Good work! You figured out how to traverse the DOM, scrape the html doc, and puts all of the desired info to the console. Well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment