Class: HNPosts::Fetcher
- Inherits:
-
Object
- Object
- HNPosts::Fetcher
- Defined in:
- lib/hnposts/fetcher.rb
Constant Summary collapse
- HN_URL =
"https://news.ycombinator.com/"
Instance Method Summary collapse
Instance Method Details
#fetch_posts ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/hnposts/fetcher.rb', line 7 def fetch_posts posts = [] post_nodes = Nokogiri::HTML(contents).css('td[class=title]:nth-of-type(3)').map {|n| n.parent} post_nodes.each_with_index do | node, indx | posts << Post.new({ post_id: (post_id node), title: (title node), url: (url node), points: (points node), comments: (comments node), position: (indx + 1) }) end posts end |