-
Notifications
You must be signed in to change notification settings - Fork 0
/
eva.rb
61 lines (52 loc) · 1.13 KB
/
eva.rb
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
module Eva
class Base
def initialize(member)
@member = member
end
end
class Course < Base
def list
# 推荐课程,在已发布课程中做推荐筛选
recommands = ::Course.open.limit(2)
# 正在学习的课程,学完并通过考核的课程不显示
checked = @member.checked_courses
invited = @member.invited_courses
list = (checked + recommands + invited).uniq
result = []
list.each_with_index do |c,i|
result << c.as_json.merge!(:has_checkin => (i < checked.length))
end
result
end
end
class Quote < Base
def single
@quote = ::Quote.tag_by("love").first
@quote.as_short_json if @quote
end
end
class Song < Base
def single
@song = ::Song.first
liked = @song.liked_by?(@member)
@song.as_json.merge!(:liked => liked)
end
end
class Person < Base
def single
::Person.first.as_json
end
end
class Media < Base
def fetch
if p = @member.has_provider?("tumblr")
data = Olive::Tumblr.new(p).user_liked_media
if @member[:tumblr]
data = data | @member[:tumblr]
end
@member.write_attribute(:tumblr,data)
@member.save
end
end
end
end