Class: CW::Rss
Overview
Instance Method Summary
collapse
#cw_chars, #exclude_non_cw_chars, #letter_group, #number_group
Instance Method Details
#article_index ⇒ Object
58
59
60
|
# File 'lib/cw/rss.rb', line 58
def article_index
@article_index || @article_index = 0
end
|
#inc_article_index ⇒ Object
54
55
56
|
# File 'lib/cw/rss.rb', line 54
def inc_article_index
@article_index += 1
end
|
#next_article ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/cw/rss.rb', line 62
def next_article
article = @rss_articles[article_index]
return unless article
inc_article_index
article.split.collect do |chars|
cw_chars(chars.strip.delete("\"").downcase)
end
end
|
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
|
# File 'lib/cw/rss.rb', line 28
def (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::.new(title).scrub
clean_desc = CW::.new(description).scrub
@rss_articles << clean_title + '. ' + clean_desc
count += 1
break if count >= article_count
end
end
end
|
#source(src) ⇒ Object
24
25
26
|
# File 'lib/cw/rss.rb', line 24
def source src
sources.has_key?(src) ? sources[src] : sources[:quotation]
end
|
#sources ⇒ Object
15
16
17
18
19
20
21
22
|
# 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
|