Class: Cline::Collectors::Feed
- Defined in:
- lib/cline/collectors/feed.rb
Class Method Summary collapse
Instance Method Summary collapse
- #entries ⇒ Object
-
#initialize(opml_str) ⇒ Feed
constructor
A new instance of Feed.
- #parse_opml(opml_node) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(opml_str) ⇒ Feed
Returns a new instance of Feed.
18 19 20 21 22 23 24 |
# File 'lib/cline/collectors/feed.rb', line 18 def initialize(opml_str) require 'rexml/document' require 'feedzirra' @opml = REXML::Document.new(opml_str) @feeds = parse_opml(@opml.elements['opml/body']) end |
Class Method Details
.collect ⇒ Object
6 7 8 9 10 11 |
# File 'lib/cline/collectors/feed.rb', line 6 def collect new(opml_path.read).entries.each do |entry| = Cline::Notification.("#{entry.title} #{entry.url}") create_or_pass , entry.published end end |
Instance Method Details
#entries ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cline/collectors/feed.rb', line 26 def entries entries = [] @feeds.map { |feed_url| Thread.fork { begin feed = Feedzirra::Feed.fetch_and_parse(feed_url) if feed.is_a?(Feedzirra::FeedUtilities) feed.entries.each { |entry| entries << entry } end rescue puts $!.class, $!. ensure Thread.pass end } }.map(&:join) entries end |
#parse_opml(opml_node) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cline/collectors/feed.rb', line 48 def parse_opml(opml_node) feeds = [] opml_node.elements.each('outline') do |el| unless el.elements.size.zero? feeds += parse_opml(el) else url = el.attributes['xmlUrl'] feeds << url if url end end feeds end |