-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathproject.rb
73 lines (62 loc) · 1.51 KB
/
project.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
62
63
64
65
66
67
68
69
70
71
72
73
require 'pstore'
require 'md5'
require 'json'
module EDash
class Project
class << self
def store
Storage.store
end
def all
projects = nil
store.transaction do
projects = store['projects'] || {}
end
projects = projects.values
projects.sort
end
def save(project)
store.transaction do
store['projects'] ||= {}
store['projects'][project.name] = project
end
end
def find(name)
store.transaction do
projects = store['projects'] || {}
projects[name]
end
end
end
attr_reader :name, :author, :status, :author_email, :author_gravatar
attr :progress, :writer => true
def <=>(other)
self.name <=> other.name
end
def initialize(params)
@name = params['project']
update_from(params)
end
def update_from(params)
@author = params['author']
@status = params['status']
if (@author && @author.size > 0)
@author_email = @author.match(/<(.*)>/)[1].gsub(' ', '+')
@author_gravatar = gravatar_uri
end
end
def gravatar_uri
"http://www.gravatar.com/avatar/#{MD5::md5(@author_email)}?s=50"
end
def to_json(*a)
{
'json_class' => self.class.name,
'name' => name,
'author' => author,
'status' => status,
'author_email' => author_email,
'author_gravatar' => author_gravatar
}.to_json(*a)
end
end
end