Class: Omnom::Source::Stackoverflow::Default

Inherits:
Base
  • Object
show all
Defined in:
lib/omnom/source/stackoverflow/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

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

#html_to_text

Constructor Details

This class inherits a constructor from Omnom::Source::Base

Instance Method Details

#after_initializeObject



8
9
10
# File 'lib/omnom/source/stackoverflow/default.rb', line 8

def after_initialize
  @url = "#{@url}#{@options[:path]}" if @options[:path].present?
end

#get_raw_postsObject



12
13
14
# File 'lib/omnom/source/stackoverflow/default.rb', line 12

def get_raw_posts
  @page.search('#questions > .question-summary')
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
# File 'lib/omnom/source/stackoverflow/default.rb', line 16

def post_attributes(node)
  link_node = node.find('.question-hyperlink')
  url = link_node.url
  title = link_node.text
  guid = url

  author_link_node = node.find('.user-details').attr_matches('href', /^\/users\/\d+\//).first
  author_name = author_link_node.text
  author_url = author_link_node.url

  answers_count = node.find('.status > strong').text.to_i
  views_count = node.find('.views').text.to_i
  votes_count = node.find('.vote-count-post > strong').text.to_i

  {
    title: title,
    description: node.find('.excerpt').text,
    guid: guid,
    url: url,
    published_at: node.find('.relativetime').time(attribute: 'title'),
    author_name: author_name,
    author_url: author_url,
    comments_count: answers_count,
    comments_url: url,
    other: {
      answers_count: answers_count,
      views_count: views_count,
      votes_count: votes_count
    }
  }
end