25 lines
624 B
Ruby
25 lines
624 B
Ruby
class Item < ActiveRecord::Base
|
|
belongs_to :feed
|
|
|
|
validates_presence_of :title, :author, :content
|
|
validates_uniqueness_of :url
|
|
|
|
default_scope order("published_at DESC")
|
|
scope :recent, limit(10)
|
|
|
|
def self.create_from_feed_entry!(feed_entry)
|
|
feed_entry.sanitize!
|
|
|
|
self.create!(
|
|
:title => feed_entry.title,
|
|
:url => feed_entry.url,
|
|
:author => feed_entry.author || "Anonymous",
|
|
:published_at => feed_entry.published,
|
|
:content => feed_entry.content || feed_entry.summary || "No content available"
|
|
)
|
|
end
|
|
|
|
def <=>(other)
|
|
self.published_at <=> other.published_at
|
|
end
|
|
end
|