Class: Cline::Collectors::Feed

Inherits:
Base
  • Object
show all
Defined in:
lib/cline/collectors/feed.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

create_or_pass

Constructor Details

#initialize(opml_str) ⇒ Feed

Returns a new instance of Feed.



21
22
23
24
25
26
27
# File 'lib/cline/collectors/feed.rb', line 21

def initialize(opml_str)
  require 'rexml/document'
  require 'active_support/deprecation'
  require 'feedzirra'

  @opml = REXML::Document.new(opml_str)
end

Class Method Details

.collectObject



8
9
10
11
12
13
14
# File 'lib/cline/collectors/feed.rb', line 8

def collect
  new(opml_path.read).entries.each do |entry|
    message = Cline::Notification.normalize_message("#{entry.title} #{entry.url}")

    create_or_pass message, entry.published
  end
end

.opml_pathObject



16
17
18
# File 'lib/cline/collectors/feed.rb', line 16

def opml_path
  opml = Pathname.new("#{Cline.cline_dir}/feeds.xml")
end

Instance Method Details

#entriesObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cline/collectors/feed.rb', line 29

def entries
  feed_urls = parse_opml(@opml.elements['opml/body'])
  entries   = []

  3.times.map { Thread.fork {
    while url = feed_urls.pop
      entries += fetch_entries(url)
    end

    Thread.pass
  } }.map(&:join)

  entries
end