Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save philsof/99433f96972e5febf8a2 to your computer and use it in GitHub Desktop.
Save philsof/99433f96972e5febf8a2 to your computer and use it in GitHub Desktop.
code-review-plonsker_and_kb-for-scraping-hn-1-building-objects-challenge

Good effort on this! Here are my notes:

  • Your runner code (which appears to be in your parser.rb file) does not seem to be utilizing any of your post class code. It is not creating a post object or printing any post info.
  • There is code in your post initialize method that is most likely not doing what you think it is doing, right here. This is because of how your add_comment method is written (see next point).
  • In your post class you have a very interesting add_comment method, which is this:
def add_comment(comment)
  symbol_id = ("id" + comment.id.to_s).to_sym
  @comments[symbol_id] = comment
end

There is a problem with this method: the first time this method is run, @comments will contain one key-value pair representing the added comment object, like this: @comments={:id=>#<Comment:0x007f8e9c9b9ec0 @id=nil, @username="No Username", @timestamp="No Time", @content="">} But then, when add_comments is run again, the entire hash gets overwritten by a new key-value pair, so that after the second time it runs, @comments then contains only this new key-value pair, like this: @comments={:id=>#<Comment:0x007f8e9d0d8b20 @id=nil, @username="No Username", @timestamp="No Time", @content="">} Thus each time your add_comments method runs, it is overwriting everything in your @comments hash.

Tip: You overthought your add_comments method. Here is what your add_comments method should look like:

def add_comments(comment)
  @comments << comment
end
  • Nice work on having a to_s method on your post and comment classes.
  • Nice work having your post initialize method call your parse_comments method.

###If you have time to refactor, see if you can meet these constraints:###

  1. Refactor your code in such a way that your runner code is simply:
post = Post.new('html-samples/hacker-news-post.html')
puts post.to_s

(Note: This would require you to refactor more than your runner code!)

  1. Be sure that the console output from puts post.to_s includes your post object attributes and the encapsulated comment object attributes (and not just the comment object attributes).

Good effort! Any questions let me know.

-Phil

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