Good effort! Here are my notes on your code:
- I can't find any runner code in your branch. (There is a
runner.rbfile, but when I run it, nothing happens.) When I add my own runner code to your runner file (by adding the lineputs postto 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
postclass attributes, but you already have this method "under the hood" because of yourattr_accessor :commentsline here. Try it: If you comment out the explicit method, your code will still work exactly the same way. - Nice work with your
Parsermodule! Here is a challenge: Could you write yourParsermodule (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_readerandattr_accessorlines 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:.commentsor justcommentsor to assign:comments=()). - Good work on your
postclassto_smethod. 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 utilizeto_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