Class: Stellar::Gradebook::Assignment

Inherits:
Object
  • Object
show all
Defined in:
lib/stellar/gradebook.rb

Overview

One assignment in the Gradebook tab.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tr, gradebook) ⇒ Assignment

Creates a submission from a <tr> element in the Gradebook assignments page.

Parameters:

  • tr (Nokogiri::XML::Element)

    a <tr> element in the Gradebook assignments page describing this assignment

  • gradebook (Stellar::Gradebook)

    Stellar client scoped to the course gradebook containing this assignment

Raises:

  • (ArgumentError)


144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/stellar/gradebook.rb', line 144

def initialize(tr, gradebook)
  @gradebook = gradebook
  @client = gradebook.client
  
  link = tr.css('a[href*=".html"]').find { |link| link.css('img').empty? }
  raise ArgumentError, 'Invalid assignment-listing <tr>' unless link
  @name = link.inner_text
  @url = URI.join tr.document.url, link['href']
  
  page = client.get_nokogiri @url
  summary_table = page.css('.gradeTable').find do |table|
    /summary/i =~ table.css('caption').inner_text
  end
  raise ArgumentError, 'Invalid assignment-listing <tr>' unless summary_table
  
  edit_link = summary_table.css('tbody tr a[href*="edit"]').first
  raise ArgumentError, 'Invalid assignment-listing <tr>' unless edit_link
  @edit_url = URI.join @url.to_s, edit_link['href']
  
  @deleted = false
end

Instance Attribute Details

#clientObject (readonly)

Generic Stellar client used to make requests.



136
137
138
# File 'lib/stellar/gradebook.rb', line 136

def client
  @client
end

#deletedObject (readonly) Also known as: deleted?

True if the homework was deleted.



128
129
130
# File 'lib/stellar/gradebook.rb', line 128

def deleted
  @deleted
end

#gradebookObject (readonly)

The gradebook that this assignment is in.



133
134
135
# File 'lib/stellar/gradebook.rb', line 133

def gradebook
  @gradebook
end

#nameObject (readonly)

Assignment name.



122
123
124
# File 'lib/stellar/gradebook.rb', line 122

def name
  @name
end

#urlObject (readonly)

URL of the assignment’s main page.



125
126
127
# File 'lib/stellar/gradebook.rb', line 125

def url
  @url
end

Instance Method Details

#delete!Object

Deletes this assignment from the Gradebook.



167
168
169
170
171
172
173
174
175
176
# File 'lib/stellar/gradebook.rb', line 167

def delete!
  return if @deleted
  
  edit_page = @client.get @edit_url
  edit_form = edit_page.form_with :action => /edit/i
  confirm_page = edit_form.submit edit_form.button_with(:name => /del/i)
  
  @deleted = true
  self
end