Module: HackerNews
- Defined in:
- lib/hnruby.rb,
lib/hnruby/comment.rb,
lib/hnruby/newsitem.rb,
lib/hnruby/storylist.rb
Overview
The HackerNews module is a set of tools for reading from Hacker News.
Simple Example
Print out information about the top news item:
require 'hnruby'
top = HackerNews::StoryList[1]
puts "Title: #{top.title}"
puts "URL: #{top.url}"
puts "Comments: #{top.comment_url}"
puts "Submitted: #{top.time}"
puts "Has #{top.points} points and #{top.comments} comments."
Accessing Content
Stories
Stories are only really accessible via index, via the HackerNews::StoryList module like in the above example.
Comments
Comments are accessed via the CommentPage class, which represents all comments on a given HN story. These are also easiest to access via StoryList:
cpage = HackerNews::StoryList[1].comment_page\
#=> "Fixing Unix Filenames (2012)" <27 Comments>
However, it’s also possible to pass a URL directly to the CommentPage constructor:
page = HackerNews::CommentPage.new\
("https://news.ycombinator.com/item?id=6644955")\
#=> "Fixing Unix Filenames (2012)" <27 Comments>
From a CommentPage, specific comments can be accessed via index:
comment = cpage[1] #=> <Comment> by user 1 day ago
Defined Under Namespace
Modules: StoryList Classes: Comment, CommentPage, NewsItem
Constant Summary collapse
- HN_URL =
Because clearly this is in danger of changing at any moment.
"https://news.ycombinator.com/"