class Stellar::Homework::Submission::Comment
A comment on a Stellar
submission.
Attributes
attachment_url[R]
URL to the file attached to the comment. Can be nil.
client[R]
Generic Stellar
client used to make requests.
deleted[R]
True if the comment was deleted.
deleted?[R]
True if the comment was deleted.
submission[R]
The submission that the comment was posted on.
text[R]
Comment
text.
Public Class Methods
new(table, submission)
click to toggle source
Creates a comment from a <table> in a Stellar
submission details page.
@param [Nokogiri::XML::Element] table a <table> element in a Stellar
submission details showing this comment
@param [Stellar::Homework::Submission] submission Stellar
client scoped to
the submission that was commented on
# 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 attachment_links = table.css('tbody tr td.announcement > a') if attachment_links.empty? @attachment_url = nil else @attachment_url = URI.join page_url, attachment_links.first['href'] end end end
Public Instance Methods
attachment_data()
click to toggle source
The contents of the file attached to this Stellar
submission comment.
@return [String] raw file data
# File lib/stellar/homework.rb, line 256 def attachment_data @attachment_url && @client.get_file(@attachment_url) end
delete!()
click to toggle source
Deletes this comment from Stellar
.
# 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_button = delete_form.button_with(:name => /delete/i) delete_form.submit delete_button @deleted = true end