class Stellar::Homework::Submission
A student's submission for an assignment.
Attributes
Generic Stellar
client used to make requests.
Comments posted on this submission.
Email of the student who authored this submission.
URL to the last file that the student submitted.
Homework
that the submission belongs to.
Name of the student who authored this submission.
Submission
time.
Public Class Methods
Creates a submission from a <tr> element in the Stellar
homework page.
@param [Nokogiri::XML::Element] tr a <tr> element in the Stellar
homework
page describing this submission
@param [Stellar::Homework] homework Stellar
client scoped to the assignment
that this submission is for
# 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 author_link = page.css('#content h4 a[href^="mailto:"]').first raise ArgumentError, 'Invalid submission-listing <tr>' end @name = author_link.inner_text @email = author_link['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
Public Instance Methods
Adds a comment to the student's submission.
@param [String] text the comment text @param [String] file_data
the content of the file attached to the comment;
by default, no file is attached
@param [String] file_mime_type if a file is attached, indicates its type;
examples: 'text/plain', 'application/pdf'
@param [String] file_name name of the file attached to the comment; by
default, 'attachment.txt'
@return [Stellar::Homework::Submission] self
# 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.button_with(:name => /submit/i) self end
The contents of the file attached to this Stellar
submission.
@return [String] raw file data
# File lib/stellar/homework.rb, line 147 def file_data @client.get_file @file_url end
Reloads the problem set's comments page.
# 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