forked from edendevelopment/edash
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcountdown.rb
57 lines (48 loc) · 1.22 KB
/
countdown.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
module EDash
class Countdown
class << self
def store
Storage.store
end
def all
countdowns = nil
store.transaction do
countdowns = store['countdowns'] || {}
end
countdowns.values
end
def save(countdown)
store.transaction do
store['countdowns'] ||= {}
store['countdowns'][countdown.id] = countdown
end
end
def find(id)
store.transaction do
countdowns = store['countdowns'] || {}
countdowns[id]
end
end
end
def self.find_or_create(params)
countdown = Countdown.find(params['id'])
return countdown if countdown
countdown = Countdown.new(params)
save(countdown)
countdown
end
def initialize(params)
@id = "coundownID"
@description = params['description']
@timestamp = Time.utc(params['year'], params['month'], params['day'], params['hour'], params['minute'])
end
attr_reader :id, :description, :timestamp
def to_json
{
'description' => description,
'timestamp' => timestamp.iso8601,
'id' => id
}.to_json
end
end
end