forked from defunkt/hurl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.rb
More file actions
66 lines (53 loc) · 1.34 KB
/
Copy pathuser.rb
File metadata and controls
66 lines (53 loc) · 1.34 KB
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
module Hurl
class User
attr_accessor :id, :login, :github_user
def initialize(github_user)
@github_user = github_user
@login = github_user.login
@id = github_user.attribs['id']
end
#
# each user has an associated list
# of hurls
#
def latest_hurl
hurls(0, 1).first
end
def second_to_last_hurl_id
hurls.any? and hurls(0, 2).size == 2 and hurls(0, 2)[1]['id']
end
def latest_hurl_id
hurls.any? and latest_hurl['id']
end
def add_hurl(id)
hurl_ids = DB.find(:users, db_id) || {}
hurl_ids[id] = Time.now
DB.save(:users, db_id, hurl_ids)
end
def remove_hurl(id)
hurl_ids = DB.find(:users, db_id) || {}
hurl_ids.delete(id)
DB.save(:users, db_id, hurl_ids)
end
def db_id
Digest::MD5.hexdigest(id.to_s)
end
def unsorted_hurls(start = 0, limit = 100)
Array(DB.find(:users, db_id)).map do |id, date|
DB.find(:hurls, id).merge('date' => Time.parse(date)) if id
end.compact
end
def hurls(start = 0, limit = 100)
unsorted_hurls(start, limit).sort_by { |h| -h['date'].to_i }
end
#
# instance methods
#
def to_s
login
end
def gravatar_url
"http://www.gravatar.com/avatar/%s" % github_user.attribs['gravatar_id']
end
end
end