Class: Stellar::Homework::Submission
- Inherits:
-
Object
- Object
- Stellar::Homework::Submission
- Defined in:
- lib/stellar/homework.rb
Overview
A student’s submission for an assignment.
Defined Under Namespace
Classes: Comment
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Generic Stellar client used to make requests.
-
#comments ⇒ Object
readonly
Comments posted on this submission.
-
#email ⇒ Object
readonly
Email of the student who authored this submission.
-
#file_url ⇒ Object
readonly
URL to the last file that the student submitted.
-
#homework ⇒ Object
readonly
Homework that the submission belongs to.
-
#name ⇒ Object
readonly
Name of the student who authored this submission.
-
#time ⇒ Object
readonly
Submission time.
Instance Method Summary collapse
-
#add_comment(text, file_data = nil, file_mime_type = 'text/plain', file_name = 'attachment.txt') ⇒ Stellar::Homework::Submission
Adds a comment to the student’s submission.
-
#file_data ⇒ String
The contents of the file attached to this Stellar submission.
-
#initialize(tr, homework) ⇒ Submission
constructor
Creates a submission from a <tr> element in the Stellar homework page.
-
#reload_comments!(page = nil) ⇒ Object
Reloads the problem set’s comments page.
Constructor Details
#initialize(tr, homework) ⇒ Submission
Creates a submission from a <tr> element in the Stellar homework page.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/stellar/homework.rb', line 110 def initialize(tr, homework) link = tr.css('a').find do |link| (/^\s*\d+\s*$/ =~ link.inner_text) && !(/grade/ =~ link['href']) end raise ArgumentError, 'Invalid submission-listing <tr>' unless link @url = URI.join tr.document.url, link['href'] @homework = homework @client = homework.client page = @client.get_nokogiri @url unless = page.css('#content h4 a[href^="mailto:"]').first raise ArgumentError, 'Invalid submission-listing <tr>' end @name = .inner_text @email = ['href'].sub /^mailto:/, '' @file_url = page.css('#rosterBox a[href*="studentWork"]').map { |link| next nil unless link.inner_text == homework.name URI.join @url.to_s, link['href'] }.reject(&:nil?).first @time = page.css('#rosterBox .instruction').map { |span| unless span.css('strong').any? { |strong| /date/i =~ strong.inner_text } next nil end time_string = span.inner_text.split(':', 2).last.strip time = DateTime.parse(time_string + ' GMT-4').to_time }.reject(&:nil?).first @add_comment_url = URI.join @url.to_s, page.css('#comments a[href*="add"]').first['href'] reload_comments! page end |
Instance Attribute Details
#client ⇒ Object (readonly)
Generic Stellar client used to make requests.
102 103 104 |
# File 'lib/stellar/homework.rb', line 102 def client @client end |
#comments ⇒ Object (readonly)
Comments posted on this submission.
96 97 98 |
# File 'lib/stellar/homework.rb', line 96 def comments @comments end |
#email ⇒ Object (readonly)
Email of the student who authored this submission.
93 94 95 |
# File 'lib/stellar/homework.rb', line 93 def email @email end |
#file_url ⇒ Object (readonly)
URL to the last file that the student submitted.
84 85 86 |
# File 'lib/stellar/homework.rb', line 84 def file_url @file_url end |
#homework ⇒ Object (readonly)
Homework that the submission belongs to.
99 100 101 |
# File 'lib/stellar/homework.rb', line 99 def homework @homework end |
#name ⇒ Object (readonly)
Name of the student who authored this submission.
90 91 92 |
# File 'lib/stellar/homework.rb', line 90 def name @name end |
#time ⇒ Object (readonly)
Submission time.
87 88 89 |
# File 'lib/stellar/homework.rb', line 87 def time @time end |
Instance Method Details
#add_comment(text, file_data = nil, file_mime_type = 'text/plain', file_name = 'attachment.txt') ⇒ Stellar::Homework::Submission
Adds a comment to the student’s submission.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/stellar/homework.rb', line 161 def add_comment(text, file_data = nil, file_mime_type = 'text/plain', file_name = 'attachment.txt') add_page = @client.get @add_comment_url add_form = add_page.form_with :action => /addcomment/i add_form.field_with(:name => /newCommentRaw/i).value = text add_form.field_with(:name => /newComment/i).value = text add_form.checkbox_with(:name => /privateComment/i).checked = :checked if file_data upload = add_form.file_uploads.first upload.file_name = file_name upload.mime_type = file_mime_type upload.file_data = file_data end add_form.submit add_form.(:name => /submit/i) self end |
#file_data ⇒ String
The contents of the file attached to this Stellar submission.
147 148 149 |
# File 'lib/stellar/homework.rb', line 147 def file_data @client.get_file @file_url end |
#reload_comments!(page = nil) ⇒ Object
Reloads the problem set’s comments page.
180 181 182 183 184 185 |
# File 'lib/stellar/homework.rb', line 180 def reload_comments!(page = nil) page ||= @client.get_nokogiri @url @comments = page.css('#comments ~ table.dataTable').map { |table| Comment.new table, self }.reject(&:nil?) end |