Class: CWG::Rss
- Inherits:
-
Object
show all
- Includes:
- TextHelpers
- Defined in:
- /Users/martyn/cw/cw_clone/lib/cw/rss.rb
Overview
Instance Method Summary
(collapse)
#cw_chars, #exclude_non_cw_chars, #letter_group, #number_group
Instance Method Details
- (Object) article_index
51
52
53
|
# File '/Users/martyn/cw/cw_clone/lib/cw/rss.rb', line 51
def article_index
@article_index || @article_index = 0
end
|
- (Object) inc_article_index
47
48
49
|
# File '/Users/martyn/cw/cw_clone/lib/cw/rss.rb', line 47
def inc_article_index
@article_index += 1
end
|
- (Object) next_article
55
56
57
58
59
60
61
62
|
# File '/Users/martyn/cw/cw_clone/lib/cw/rss.rb', line 55
def next_article
temp = @rss_articles[article_index]
return unless temp
inc_article_index
quote = ''
temp.map { |i| quote += i }
(quote.split.collect { |article| cw_chars(article.strip.delete("\"").downcase)})
end
|
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File '/Users/martyn/cw/cw_clone/lib/cw/rss.rb', line 24
def (src, article_count = 3)
require 'feedjira'
require "htmlentities"
require 'sanitize'
coder = HTMLEntities.new
url = source(src)
feed = Feedjira::Feed.fetch_and_parse url
entry_count = 0
@rss_articles = []
feed.entries.each do |entry|
title = entry.title
unless(title.include?('VIDEO:') ||
title.include?('In pictures:') ||
title.include?('Morning business round-up'))
words = entry.summary
entry_count += 1
end
@rss_articles << (Sanitize.clean coder.decode words).split(',')
break if entry_count >= article_count
end
end
|
- (Object) source(src)
20
21
22
|
# File '/Users/martyn/cw/cw_clone/lib/cw/rss.rb', line 20
def source src
sources.has_key?(src) ? sources[src] : sources[:quotation]
end
|
- (Object) sources
11
12
13
14
15
16
17
18
|
# File '/Users/martyn/cw/cw_clone/lib/cw/rss.rb', line 11
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
|