lib/feedzirra/feed_utilities.rb in pauldix-feedzirra-0.0.1 vs lib/feedzirra/feed_utilities.rb in pauldix-feedzirra-0.0.2
- old
+ new
@@ -24,11 +24,11 @@
new_entries.size > 0
end
def update_from_feed(feed)
self.new_entries += find_new_entries_for(feed)
- self.entries += self.new_entries
+ self.entries.unshift(*self.new_entries)
updated! if UPDATABLE_ATTRIBUTES.any? { |name| update_attribute(feed, name) }
end
def update_attribute(feed, name)
@@ -37,17 +37,32 @@
if old_value != new_value
send("#{name}=", new_value)
end
end
+ def sanitize_entries!
+ entries.each {|entry| entry.sanitize!}
+ end
+
private
def updated!
@updated = true
end
def find_new_entries_for(feed)
- feed.entries.inject([]) { |result, entry| result << entry unless existing_entry?(entry); result }
+ # this implementation is a hack, which is why it's so ugly.
+ # it's to get around the fact that not all feeds have a published date.
+ # however, they're always ordered with the newest one first.
+ # So we go through the entries just parsed and insert each one as a new entry
+ # until we get to one that has the same url as the the newest for the feed
+ latest_entry = self.entries.first
+ found_new_entries = []
+ feed.entries.each do |entry|
+ break if entry.url == latest_entry.url
+ found_new_entries << entry
+ end
+ found_new_entries
end
def existing_entry?(test_entry)
entries.any? { |entry| entry.url == test_entry.url }
end
\ No newline at end of file