Class: Everyx::PeriodicTasks::RSSNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/everyx.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRSSNotifier

Returns a new instance of RSSNotifier.



34
35
36
37
# File 'lib/everyx.rb', line 34

def initialize
  @uri, @delay = nil, ( 60 * 15 )
  @last = nil
end

Instance Attribute Details

#delayObject (readonly)

Returns the value of attribute delay.



32
33
34
# File 'lib/everyx.rb', line 32

def delay
  @delay
end

#uriObject (readonly)

Returns the value of attribute uri.



31
32
33
# File 'lib/everyx.rb', line 31

def uri
  @uri
end

Instance Method Details

#runObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/everyx.rb', line 39

def run
  rss = RSS::Parser.parse( open(@uri) {|s| s.read }, false )
  new = []
  first_new = nil
  rss.items.each do |item|
    if item.link != @last
      first_new = item.link unless first_new
      new << item.title
    else
      break
    end
  end

  @last = first_new if first_new

  if new.size > 0
    puts "#{new.size} items"
    NServer::Client.try_notify( new.join("\n") )
  else
    puts "No new items."
  end
end