Class: FeedReader
- Inherits:
-
Object
- Object
- FeedReader
- Defined in:
- lib/imap-feeder/feedreader.rb
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
- #conv(str) ⇒ Object
- #get_new(archive) ⇒ Object
-
#initialize(feed_url) ⇒ FeedReader
constructor
A new instance of FeedReader.
- #number_of_entries ⇒ Object
- #time_from(item) ⇒ Object
Constructor Details
#initialize(feed_url) ⇒ FeedReader
Returns a new instance of FeedReader.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/imap-feeder/feedreader.rb', line 19 def initialize(feed_url) @feed_url = feed_url @feed = SimpleRSS.parse(open(feed_url)) @encoding = @feed.source[/encoding=["'](.*?)["']/, 1] if not @encoding $log.warn "No encoding found for #{feed_url}, defaulting to UTF-8." @encoding = "UTF-8" end end |
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
17 18 19 |
# File 'lib/imap-feeder/feedreader.rb', line 17 def @messages end |
Instance Method Details
#conv(str) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/imap-feeder/feedreader.rb', line 30 def conv(str) Iconv.iconv("UTF-8", @encoding, str).first rescue Iconv::IllegalSequence => e $log.error "IConv reports an IllegalSequence: #{e.} from #{str}" return str end |
#get_new(archive) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/imap-feeder/feedreader.rb', line 41 def get_new(archive) return [] if not @feed archive ||= [] if archive.include?("") $log.warn "Title is empty, that should never happen! Aborting #{@feed_url}." return [] end = [] @feed.entries.each do |item| body = conv(item.content_encoded || item.content || item.summary || item.description) = Message.new( :title => conv(item.title), :time => time_from(item), :body => body, :from => conv(item.), :url => conv(item.link) ) item_identifier = .generate_identifier if archive.include? item_identifier short_name = .title[0..30] short_name << "…" if .title.length > 30 $log.debug "Already have '#{short_name}'." else << end end end |
#number_of_entries ⇒ Object
37 38 39 |
# File 'lib/imap-feeder/feedreader.rb', line 37 def number_of_entries @feed.entries.size end |
#time_from(item) ⇒ Object
77 78 79 80 |
# File 'lib/imap-feeder/feedreader.rb', line 77 def time_from item return nil if not item item.published || item.pubDate || item.date_published || item.updated || nil end |