Class: Feed2Mail::Report

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Report

Returns a new instance of Report.



7
8
9
10
11
# File 'lib/feed2mail/report.rb', line 7

def initialize(config)
  @feeds = config.feeds
  @items = []
  @history = History.new config
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



5
6
7
# File 'lib/feed2mail/report.rb', line 5

def items
  @items
end

Instance Method Details

#mail(opts) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/feed2mail/report.rb', line 26

def mail(opts)
  Pony.mail(
    :via_options  => { :arguments => '-i' },
    :charset      => 'UTF-8',
    :from         => opts[:from],
    :to           => opts[:to],
    :subject      => 'Feed2Mail: new feed items published',
    :body         => to_s
  )
end

#seen?(item) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/feed2mail/report.rb', line 49

def seen?(item)
  @history.has?(item.uri) ? true : false
end

#to_sObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/feed2mail/report.rb', line 13

def to_s
  out = ''
  @items.each do |i|
    out << <<-eoh
#{i.title}
#{i.uri}

    eoh
  end

  out
end

#updateObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/feed2mail/report.rb', line 37

def update
  @feeds.each do |f|
    f.items.each do |i|
      unless seen? i
        @items << i
        @history << i.uri
      end
    end
  end
  @history.save!
end