-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask.rb
More file actions
72 lines (55 loc) · 1.39 KB
/
task.rb
File metadata and controls
72 lines (55 loc) · 1.39 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
67
68
69
70
71
72
# frozen_string_literal: true
# A wrapper for the task JSON from ClickUp
class Task
def initialize(data)
@data = data
end
def id
@data['id']
end
def name
@data['name']
end
def description
@data['description'].to_s.strip
end
def custom_fields
@data['custom_fields']
end
def tags
@data['tags']
end
def status
@data['status']['status']
end
# @return [Time, nil] the time the task was created
def due_date
return nil if @data['due_date'].nil?
Time.at @data['due_date'].to_i / 1000
end
def start_date
return nil if @data['start_date'].nil?
Time.at @data['start_date'].to_i / 1000
end
# @return [String] a link to the canvas html_url
# @see Assignment#url
def canvas_link
custom_fields.find { |field| field['name'] == 'Canvas Link' }['value']
end
# @return [String] the name of the class based on the custom field
def class_name
field = custom_fields.find { |custom_field| custom_field['name'] == 'Class' }
value = field['value']
field['type_config']['options'][value]['name']
end
def grade
custom_fields.find { |field| field['name'] == 'Grade' }['value']
end
# Whether or not this task is ignored
def ignored?
!tags.find { |tag| tag['name'].downcase == 'ignored' }.nil?
end
def submissionless?
!tags.find { |tag| tag['name'].downcase == 'submissionless' }.nil?
end
end