Class: Stellar::Homework::Submission::Comment
- Inherits:
-
Object
- Object
- Stellar::Homework::Submission::Comment
- Defined in:
- lib/stellar/homework.rb
Overview
A comment on a Stellar submission.
Instance Attribute Summary collapse
-
#attachment_url ⇒ Object
readonly
URL to the file attached to the comment.
-
#author ⇒ Object
readonly
Person who posted the comment.
-
#client ⇒ Object
readonly
Generic Stellar client used to make requests.
-
#deleted ⇒ Object
(also: #deleted?)
readonly
True if the comment was deleted.
-
#submission ⇒ Object
readonly
The submission that the comment was posted on.
-
#text ⇒ Object
readonly
Comment text.
Instance Method Summary collapse
-
#attachment_data ⇒ String
The contents of the file attached to this Stellar submission comment.
-
#delete! ⇒ Object
Deletes this comment from Stellar.
-
#initialize(table, submission) ⇒ Comment
constructor
Creates a comment from a <table> in a Stellar submission details page.
Constructor Details
#initialize(table, submission) ⇒ Comment
Creates a comment from a <table> in a Stellar submission details page.
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/stellar/homework.rb', line 211 def initialize(table, submission) @submission = submission @client = @submission.client page_url = table.document.url @author = table.css('thead tr th.announcedBy').first.inner_text unless content = table.css('tbody tr td.announcement').first raise 'Invalid submission comment table' end if (deleted_text = table.css('tbody tr td.announcement > em').first) && deleted_text.inner_text == 'deleted' @deleted = true @text = nil @attachment_url = nil else @deleted = false unless delete_link = table.css('thead a[href*="delete"]').first raise ArgumentError, 'Invalid submission comment table' end @delete_url = URI.join page_url, delete_link['href'] @text = content.css('p').inner_text = table.css('tbody tr td.announcement > a') if .empty? @attachment_url = nil else @attachment_url = URI.join page_url, .first['href'] end end end |
Instance Attribute Details
#attachment_url ⇒ Object (readonly)
URL to the file attached to the comment. Can be nil.
194 195 196 |
# File 'lib/stellar/homework.rb', line 194 def @attachment_url end |
#author ⇒ Object (readonly)
Person who posted the comment.
190 191 192 |
# File 'lib/stellar/homework.rb', line 190 def @author end |
#client ⇒ Object (readonly)
Generic Stellar client used to make requests.
203 204 205 |
# File 'lib/stellar/homework.rb', line 203 def client @client end |
#deleted ⇒ Object (readonly) Also known as: deleted?
True if the comment was deleted.
196 197 198 |
# File 'lib/stellar/homework.rb', line 196 def deleted @deleted end |
#submission ⇒ Object (readonly)
The submission that the comment was posted on.
201 202 203 |
# File 'lib/stellar/homework.rb', line 201 def submission @submission end |
#text ⇒ Object (readonly)
Comment text.
192 193 194 |
# File 'lib/stellar/homework.rb', line 192 def text @text end |
Instance Method Details
#attachment_data ⇒ String
The contents of the file attached to this Stellar submission comment.
256 257 258 |
# File 'lib/stellar/homework.rb', line 256 def @attachment_url && @client.get_file(@attachment_url) end |
#delete! ⇒ Object
Deletes this comment from Stellar.
244 245 246 247 248 249 250 251 |
# File 'lib/stellar/homework.rb', line 244 def delete! return if @deleted delete_page = @client.get @delete_url delete_form = delete_page.form_with(:action => /delete/i) = delete_form.(:name => /delete/i) delete_form.submit @deleted = true end |