Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save philsof/bb3ab0d39fd01ba27e66 to your computer and use it in GitHub Desktop.
Save philsof/bb3ab0d39fd01ba27e66 to your computer and use it in GitHub Desktop.
Code review for pair-mirascarvalone,superboyblue branch on scraping-hn-1-building-objects-challenge

Good effort! Here are my notes on your code:

  • I can't find any runner code in your branch. (There is a runner.rb file, but when I run it, nothing happens.) When I add my own runner code to your runner file (by adding the line puts post to the end of your runner file), and then run the file, I get this output:
A/B testing mistakes | Hacker News (Hacker News ID: 5003980)
    URL: http://visualwebsiteoptimizer.com/split-testing-blog/seven-ab-testing-mistakes-to-stop-in-2013/
    Author: ankneo
    Points: 53

    Comments:
    I recently implemented A/B testing on a client's site using one of these Javascript-based A/B testing tools (but not this one).I hadn't used one before, so wanted to verify the data would actually be accurate.I did an A/A test, basically testing the same exact page––expecting the results would be the same.Not only were the results not the same, but they were off by a wide margin.Given this, I don't know how I'm supposed to trust any of the data.Has anyone else had experiences like this? Is A/B testing in Javascript just not as reliable?-----
/Users/Phil/Desktop/Dev/DBC/Mentoring/ChorusFrogs/scraping-hn-1-building-objects-challenge/post.rb:37:in `block in to_s': undefined method `comment_id' for #<Nokogiri::XML::Element:0x007fd4e10633b8> (NoMethodError)
	from /Users/Phil/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/nokogiri-1.6.7/lib/nokogiri/xml/node_set.rb:187:in `block in each'
	from /Users/Phil/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/nokogiri-1.6.7/lib/nokogiri/xml/node_set.rb:186:in `upto'
	from /Users/Phil/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/nokogiri-1.6.7/lib/nokogiri/xml/node_set.rb:186:in `each'
	from /Users/Phil/Desktop/Dev/DBC/Mentoring/ChorusFrogs/scraping-hn-1-building-objects-challenge/post.rb:35:in `to_s'
	from runner.rb:13:in `puts'
	from runner.rb:13:in `puts'
	from runner.rb:13:in `<main>'

So it looks like your code, as it is, successfully puts the post info, and the info for one comment, but then hits an error. Remember: You need runner code to run the program, so you can debug any issues that occur when the code is run, and so that other people can run your code.

  • You explicitly wrote a reader method for one of your post class attributes, but you already have this method "under the hood" because of your attr_accessor :comments line here. Try it: If you comment out the explicit method, your code will still work exactly the same way.
  • Nice work with your Parser module! Here is a challenge: Could you write your Parser module (and also the rest of your code) in such a way that it could handle any Hacker News post URL, not just the specific one from this challenge? You can do it!
  • Remember: your attr_reader and attr_accessor lines are creating read and write methods for your attributes. This means that, to reference/assign these attributes, you do not need to directly reference/assign the instance variables (for example: @comments) but instead can reference/assign those variables via their reader/writer methods (for example: .comments or just comments or to assign: comments=()).
  • Good work on your post class to_s method. Take a look at the "Some tips on using to_s" part of this code review for another pair to get some tips on how to better utilize to_s.

If you have time, revisit this code to get it to print the post and all of the comment objects to the console. You can do it!

Any questions let me know. I am here to help.

-Phil

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