forked from stringer-rss/stringer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeed.rb
More file actions
40 lines (32 loc) · 745 Bytes
/
feed.rb
File metadata and controls
40 lines (32 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class Feed < ActiveRecord::Base
has_many :stories, -> {order "published desc"} , dependent: :delete_all
validates_uniqueness_of :url
STATUS = { green: 0, yellow: 1, red: 2 }
def status
STATUS.key(read_attribute(:status))
end
def status=(s)
write_attribute(:status, STATUS[s])
end
def status_bubble
return :yellow if status == :red && stories.any?
status
end
def unread_stories
stories.where('is_read = ?', false)
end
def has_unread_stories
unread_stories.any?
end
def as_fever_json
{
id: self.id,
favicon_id: 0,
title: self.name,
url: self.url,
site_url: self.url,
is_spark: 0,
last_updated_on_time: self.last_fetched.to_i
}
end
end