Class: Omnom::Source::Reddit::Default
- Defined in:
- lib/omnom/source/reddit/default.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Base
#config, #feed_key, #key, #options, #settings, #source_id
Instance Method Summary collapse
Methods inherited from Base
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
#after_initialize ⇒ Object
8 9 10 |
# File 'lib/omnom/source/reddit/default.rb', line 8 def after_initialize @url = "#{@url}#{@options[:subreddit]}" if @options[:subreddit].present? end |
#get_raw_posts ⇒ Object
12 13 14 |
# File 'lib/omnom/source/reddit/default.rb', line 12 def get_raw_posts @page.search('#siteTable > .link') end |
#post_attributes(node) ⇒ Object
16 17 18 19 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 |
# File 'lib/omnom/source/reddit/default.rb', line 16 def post_attributes(node) thumbnail_node = node.find('a.thumbnail > img') thumbnail_url = thumbnail_node.attr('src') if thumbnail_node.present? comments_node = node.drill( [:find, '.flat-list.buttons'], [:text_matches, /^(\d+) comments$/i], :first ) if comments_node comments_count = comments_node.matches[1] comments_url = comments_node.url else comments_node = node.drill( [:find, '.flat-list.buttons'], [:text_equals, 'comment'], :first ) if comments_node comments_count = 0 comments_url = comments_node.url end end title_node = node.find('p.title a.title') = node.find('.tagline author') if = .text = .url end { title: title_node.text, guid: node.attr('data-fullname'), url: title_node.url, published_at: node.find('.tagline time').time(attribute: 'datetime'), thumbnail_url: thumbnail_url, author_name: , author_url: , comments_count: comments_count, comments_url: comments_url, other: { likes_count: node.find('.score.unvoted').text.to_i } } end |