Class: FeedsuckerFeed

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/feedsucker_feed.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.suck_all!Object



39
40
41
# File 'app/models/feedsucker_feed.rb', line 39

def self.suck_all!
  self.find(:all).each {|feed| feed.suck!}
end

Instance Method Details

#before_createObject



13
14
15
16
# File 'app/models/feedsucker_feed.rb', line 13

def before_create
  self.number_of_posts ||= 0 # Load all entries/posts by default
  self.delete_preview ||= true # delete all old posts by default
end

#suck!Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/feedsucker_feed.rb', line 18

def suck!
  #items = self.xpath_post_url ? xml_feed_items : rss_or_atom_feed_items
  items = xml_feed_items
  if items.any?
    last_item = self.number_of_posts > 0 ? self.number_of_posts : items.size
    self.posts.destroy_all if self.delete_preview
    items[0..last_item-1].each do |item|
      unless FeedsuckerPost.find_by_url(item[:post_url])
        self.posts << FeedsuckerPost.create(
        :feedsucker_feed_id => self.id,
        :blog_title => item[:blog_title],
        :blog_url => item[:blog_url],
        :title => item[:post_title],
        :content => item[:post_content],
        :date => item[:post_date],
        :url => item[:post_url])
      end
    end
  end
end