class CW::Rss

class Rss

Public Instance Methods

article_index() click to toggle source
# File lib/cw/rss.rb, line 58
def article_index
  @article_index || @article_index = 0
end
inc_article_index() click to toggle source
# File lib/cw/rss.rb, line 54
def inc_article_index
  @article_index += 1
end
next_article() click to toggle source
read_rss(src, article_count = 3) click to toggle source
# File lib/cw/rss.rb, line 28
    def read_rss(src, article_count = 3)

      Cfg.config.params["words_counted"] = true
      @rss_articles = []
      count = 0
      coder = HTMLEntities.new
      url   = source(src)
      content = HTTPClient.new.get_content(url)
      document = Oga.parse_xml(content)
      document.xpath('rss/channel/item').each do |item|
        title = item.at_xpath('title').text
        description = item.at_xpath('description').text
        unless(title.include?('VIDEO:') ||
               title.include?('In pictures:') ||
               title.include?('Morning business round-up'))
          clean_title = CW::RSSClean.new(title).scrub
          clean_desc = CW::RSSClean.new(description).scrub
#          @rss_articles << Sanitize.clean(coder.decode(title)) + '. ' +
          #                           Sanitize.clean(coder.decode(description))
          @rss_articles << clean_title + '. ' + clean_desc
          count += 1
          break if count >= article_count
        end
      end
    end
source(src) click to toggle source
# File lib/cw/rss.rb, line 24
def source src
  sources.has_key?(src) ? sources[src] : sources[:quotation]
end
sources() click to toggle source
# File lib/cw/rss.rb, line 15
def sources
  {
    bbc:       'http://feeds.bbci.co.uk/news/rss.xml',
    reuters:   'http://feeds.reuters.com/Reuters/worldNews?format=xml',
    guardian:  'http://www.theguardian.com/world/rss',
    quotation: 'http://feeds.feedburner.com/quotationspage/qotd'
  }
end