class Stellar::Gradebook::Student
Attributes
Generic Stellar
client used to make requests.
The student's e-mail.
The course Gradebook
that this student entry belongs to.
The student's full name.
URL of the student's page of grades in the Gradebook
.
Public Class Methods
Creates a Stellar
client scoped to a student's Gradebook
page.
@param [URI] url URL to the student's grade page @param [Stellar::Gradebook] gradebook Stellar
client scoped to the
course gradebook containing this assignment
# File lib/stellar/gradebook.rb, line 270 def initialize(url, email, name, gradebook) @url = url @email = email @name = name @gradebook = gradebook @client = gradebook.client @grades = nil @input_names = nil @comment = nil end
Public Instance Methods
The instructor's comment for the student.
@return [String] the content of the comment
# File lib/stellar/gradebook.rb, line 293 def comment reload! unless @comment @comment end
The student's grades for all assignments.
@return [Hash] map between assignment names and the student's scores
# File lib/stellar/gradebook.rb, line 285 def grades reload! unless @grades @grades end
Reloads the information in the student's grades page.
@return [Stellar::Gradebook::Student] self, for easy call chaining
# File lib/stellar/gradebook.rb, line 301 def reload! page = @client.get_nokogiri @url @grades = {} @input_names = {} page.css('.gradeTable tbody tr').each do |tr| name = tr.css('a[href*="assignment"]').inner_text input_field = tr.css('input[type="text"][name*="oints"]').first @input_names[name] = input_field['name'] @grades[name] = input_field['value'].empty? ? nil : input_field['value'].to_f end @comment = page.css('textarea[name*="comment"]').inner_text self end
Changes the comment on the student's grades page.
@param [String] text the new comment text @return [Stellar::Gradebook::Student] self, for easy call chaining
# File lib/stellar/gradebook.rb, line 342 def update_comment(text) page = @client.get @url grade_form = page.form_with :action => /detail/i grade_form.field_with(:name => /comment/i).value = text grade_form.submit grade_form.button_with(:class => /save/) reload! end
Changes some of the student's grades.
@param [Hash] new_grades maps assignment names to the desired scores @return [Stellar::Gradebook::Student] self, for easy call chaining
# File lib/stellar/gradebook.rb, line 322 def update_grades(new_grades) reload! unless @input_names page = @client.get @url grade_form = page.form_with :action => /detail/i new_grades.each do |assignment_name, new_grade| unless input_name = @input_names[assignment_name] raise ArgumentError, "Invalid assignment #{assignment_name}" end grade_form.field_with(:name => input_name).value = new_grade.to_s end grade_form.submit grade_form.button_with(:class => /save/) reload! end