-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathassignment.rb
88 lines (68 loc) · 1.99 KB
/
assignment.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# frozen_string_literal: true
require 'time'
# A wrapper for the assignment JSON from Canvas
class Assignment
def initialize(data)
@data = data
end
# get the assignment name
def name
@data['name']
end
# A textual representation of the description
# @return [String] the description
def description
return '' if @data['description'].nil?
Nokogiri.parse(@data['description'].gsub(" ", " ")).text.strip
end
# @return [String] the URL to access the assignment
def url
# noinspection HttpUrlsUsage I AM FIXING IT
@data['htmlUrl'].gsub("http://", "https://")
end
# @return [Time, nil] the due date, or nil if there is no due date
def due_date
return nil if @data['dueAt'].nil?
Time.parse @data['dueAt']
end
# An assignment may only unlock at a certain time. If this is the case, this will not be nil.
# @return [Time, nil] the unlock date, or nil if there is not one
def unlocks_at
return nil if @data['unlockAt'].nil?
Time.parse @data['unlockAt']
end
# The submission types for this assignment
# @return [Array<String>] the submission types
def types
@data['submissionTypes']
end
# Returns the submission nodes for this assignment
# @return [Array] an array of Submission objects
def submissions
@data['submissionsConnection']['nodes']
end
# Returns if the assignment has a submission and the submission grade is not nil
# @return [Boolean] true if the assignment is graded
def graded?
return false if submissions.empty?
submissions[0]['grade'] != nil
end
def grade
return nil unless graded?
submissions[0]['grade']
end
# Return if this assignment has any submissions
# @return [Boolean] true if the assignment has submissions
def submitted?
!submissions.empty?
end
# Whether an assignment expects a submission
def expects_submission?
@data['expectsSubmission']
end
def status
return "Graded" if graded?
return "Submitted" if submitted?
"To Do"
end
end