Class: Omnom::Source::HackerNews::Default
- Defined in:
- lib/omnom/source/hacker_news/default.rb
Instance Attribute Summary
Attributes inherited from Base
#config, #feed_key, #key, #options, #settings, #source_id
Instance Method Summary collapse
Methods inherited from Base
#after_initialize, config, configure, cron, every, feed_url, full_key, guid_namespace, icon, icon_from_url, inherited, #initialize, key, required_config, required_options, #update, url
Methods included from ParserMethods
Constructor Details
This class inherits a constructor from Omnom::Source::Base
Instance Method Details
#get_raw_posts ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/omnom/source/hacker_news/default.rb', line 8 def get_raw_posts first_title = @page.search('td.title').first table = first_title.ancestors('table').first rows = table.>('tr') row_sets = rows.each_slice(3).to_a.collect do |row_set| doc = Nokogiri::HTML(row_set.collect { |row| row.to_s }.join) doc.uri = @page.uri doc end row_sets end |
#post_attributes(node) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/omnom/source/hacker_news/default.rb', line 20 def post_attributes(node) title_node = node.find('td.title:eq(3)') = node.find('body > tr:eq(2) > td.subtext') return nil if title_node.blank? url = title_node.find('a').url published_at = .time = .search('a').attr_matches('href', /^user\?id=/).first if = .url = .text end comments_link = .search('a').text_matches(/(\d+) comments/).first if comments_link comments_count = comments_link.matches[1].to_i comments_url = comments_link.url else comments_count = 0 comments_url = url end score_node = .search('span').attr_matches('id', /score_(\d+)/).first return nil if score_node.blank? points_count = score_node.text[/(\d+) points/, 1] points_count = points_count.to_i if points_count { title: title_node.find('a').text, guid: score_node.matches[1], url: url, published_at: published_at, author_name: , author_url: , comments_count: comments_count, comments_url: comments_url, other: { points_count: points_count } } end |