Sha256: 279a58f824c69a679f3032486ea3110cde0aaf2d1226f490da518c27af7655cc

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 KB

Contents

module Gandalf
  class Seed
    include DataMapper::Resource

    property :id, Serial
    property :include_update, Boolean, :index => true
    property :interval_update, Integer
    property :url, String, :length => 255, :unique_index => true
    
    def to_json
      {:id => id,
       :include_update => include_update,
       :interval_update => interval_update,
       :url => url}.to_json
    end
  end

  class Post
    include DataMapper::Resource

    property :id, Serial, :field => 'psid'
    property :channel_id, Integer, :length => 11, :index => true
    property :link, Text, :length => 255
    property :title, String, :length => 255
    property :author, String, :lazy => true
    property :pub_date, DateTime, :field => 'pubDate'
    property :update_date, DateTime, :field => 'updateDate', :default => DateTime.now
    property :description, Text
    property :cache_link, String, :length => 32, :unique_index => true

    belongs_to :seed, :child_key => [:channel_id]

    def clean!
      self.title = self.title[0,255] if self.title
      if self.description
        self.description.gsub!(/\<[^\>]+\>|\n|&nbsp;/,' ')
        self.description.gsub!(/&gt;/,'<')
        self.description.gsub!(/&lt;/,'>')
        self.description.gsub!(/\s{2,}/,' ')
        self.description.strip!
        self.description = nil if self.description = ""
      end
    end

    def Post.parse(feed)
      feed.entries.map do |entry|
        post = self.new({
          :title => entry.title,
          :link => entry.url,
          :author => entry.author,
          :description => entry.summary,
          :pub_date => entry.published.to_datetime,
          :cache_link => Digest::MD5.hexdigest(entry.url)
        })
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gandalf-0.0.4 lib/gandalf/models.rb