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 authorted 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.
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.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/stellar/homework.rb', line 107 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, 'Invalud 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 @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.
99 100 101 |
# File 'lib/stellar/homework.rb', line 99 def client @client end |
#comments ⇒ Object (readonly)
Comments posted on this submission.
93 94 95 |
# File 'lib/stellar/homework.rb', line 93 def comments @comments end |
#email ⇒ Object (readonly)
Email of the student who authorted this submission.
90 91 92 |
# File 'lib/stellar/homework.rb', line 90 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.
96 97 98 |
# File 'lib/stellar/homework.rb', line 96 def homework @homework end |
#name ⇒ Object (readonly)
Name of the student who authored this submission.
87 88 89 |
# File 'lib/stellar/homework.rb', line 87 def name @name 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.
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/stellar/homework.rb', line 151 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.
137 138 139 |
# File 'lib/stellar/homework.rb', line 137 def file_data @client.get_file @file_url end |
#reload_comments!(page = nil) ⇒ Object
Reloads the problem set’s comments page.
170 171 172 173 174 175 |
# File 'lib/stellar/homework.rb', line 170 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 |