Class: FeedReader
- Inherits:
-
Object
- Object
- FeedReader
- Defined in:
- lib/imap-feeder/feedreader.rb
Constant Summary collapse
- DEFAULT_ENCODING =
"UTF-8"
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.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/imap-feeder/feedreader.rb', line 21 def initialize(feed_url) @feed_url = feed_url @feed = SimpleRSS.parse(open(feed_url)) @encoding = @feed.source[/encoding=["'](.*?)["']/, 1] if not @encoding $log.info "No encoding found for #{feed_url}, defaulting to #{DEFAULT_ENCODING}." @encoding = DEFAULT_ENCODING 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
32 33 34 35 36 37 |
# File 'lib/imap-feeder/feedreader.rb', line 32 def conv(str) Iconv.iconv(DEFAULT_ENCODING, @encoding, str).first rescue Iconv::IllegalSequence => e $log.error "IConv reports an IllegalSequence: #{e.} from #{str}" return str end |
#get_new(archive) ⇒ Object
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 76 77 |
# File 'lib/imap-feeder/feedreader.rb', line 43 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
39 40 41 |
# File 'lib/imap-feeder/feedreader.rb', line 39 def number_of_entries @feed.entries.size end |
#time_from(item) ⇒ Object
79 80 81 82 |
# File 'lib/imap-feeder/feedreader.rb', line 79 def time_from item return nil if not item item.published || item.pubDate || item.date_published || item.updated || nil end |