-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfriend.moon
81 lines (62 loc) · 1.74 KB
/
friend.moon
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
74
75
76
77
78
79
80
81
colors = require "term.colors"
class
new: (name, opt) =>
unless name
error "missing 'name' argument", 0
@name = name
-- possible status are: received, asked, true friend
@status = opt.status or "unknown"
@servicesConfigured = opt.services or opt.servicesConfigured or {}
@givenTokens = opt.given or opt.givenTokens or {}
@wantsTokens = opt.wants or opt.wantsTokens or {}
-- Tokens that are both “given” and “wanted”.
@validatedTokens = [token for token in *@givenTokens when @\wants token]
services: (service) =>
for e in *@servicesConfigured
if e == service
return true
false
wants: (token) =>
for e in *@wantsTokens
if e == token
return true
false
validated: (token) =>
for e in *@validatedTokens
if e == token
return true
false
str: =>
printStr = "#{@name}: (friendship #{@status}): "
unless #@validatedTokens == 0
printStr ..= "(wants + given): "
for token in *@validatedTokens
printStr ..= "#{token},"
unless #@wantsTokens == 0
printStr ..= "; (wants): "
for token in *@wantsTokens
printStr ..= "#{token},"
unless #@givenTokens == 0
printStr ..= "; (given): "
for token in *@givenTokens
printStr ..= "#{token},"
printStr
print: =>
printStr = "#{@name}: "
color = switch @status
when "true friend"
colors.green
when "asked"
colors.yellow
when "received"
colors.blue
else
(...) -> ...
printStr ..= color " (friendship #{@status})"
for token in *@validatedTokens
printStr ..= "\n\t(wants + given): " .. colors.green("#{token}")
for token in *@wantsTokens
printStr ..= "\n\t(wants): " .. colors.yellow("#{token}")
for token in *@givenTokens
printStr ..= "\n\t(given): " .. colors.blue("#{token}")
print printStr