Class: Stellar::Gradebook::Student
- Inherits:
-
Object
- Object
- Stellar::Gradebook::Student
- Defined in:
- lib/stellar/gradebook.rb
Overview
Stellar client scoped to a student’s Gradebook page.
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Generic Stellar client used to make requests.
-
#email ⇒ Object
readonly
The student’s e-mail.
-
#gradebook ⇒ Object
readonly
The course Gradebook that this student entry belongs to.
-
#name ⇒ Object
readonly
The student’s full name.
-
#url ⇒ Object
readonly
URL of the student’s page of grades in the Gradebook.
Instance Method Summary collapse
-
#comment ⇒ String
The instructor’s comment for the student.
-
#grades ⇒ Hash
The student’s grades for all assignments.
-
#initialize(url, email, name, gradebook) ⇒ Student
constructor
Creates a Stellar client scoped to a student’s Gradebook page.
-
#reload! ⇒ Stellar::Gradebook::Student
Reloads the information in the student’s grades page.
-
#update_comment(text) ⇒ Stellar::Gradebook::Student
Changes the comment on the student’s grades page.
-
#update_grades(new_grades) ⇒ Stellar::Gradebook::Student
Changes some of the student’s grades.
Constructor Details
#initialize(url, email, name, gradebook) ⇒ Student
Creates a Stellar client scoped to a student’s Gradebook page.
270 271 272 273 274 275 276 277 278 279 280 |
# 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 |
Instance Attribute Details
#client ⇒ Object (readonly)
Generic Stellar client used to make requests.
263 264 265 |
# File 'lib/stellar/gradebook.rb', line 263 def client @client end |
#email ⇒ Object (readonly)
The student’s e-mail.
254 255 256 |
# File 'lib/stellar/gradebook.rb', line 254 def email @email end |
#gradebook ⇒ Object (readonly)
The course Gradebook that this student entry belongs to.
260 261 262 |
# File 'lib/stellar/gradebook.rb', line 260 def gradebook @gradebook end |
#name ⇒ Object (readonly)
The student’s full name.
251 252 253 |
# File 'lib/stellar/gradebook.rb', line 251 def name @name end |
#url ⇒ Object (readonly)
URL of the student’s page of grades in the Gradebook.
257 258 259 |
# File 'lib/stellar/gradebook.rb', line 257 def url @url end |
Instance Method Details
#comment ⇒ String
The instructor’s comment for the student.
293 294 295 296 |
# File 'lib/stellar/gradebook.rb', line 293 def comment reload! unless @comment @comment end |
#grades ⇒ Hash
The student’s grades for all assignments.
285 286 287 288 |
# File 'lib/stellar/gradebook.rb', line 285 def grades reload! unless @grades @grades end |
#reload! ⇒ Stellar::Gradebook::Student
Reloads the information in the student’s grades page.
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# 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 |
#update_comment(text) ⇒ Stellar::Gradebook::Student
Changes the comment on the student’s grades page.
342 343 344 345 346 347 348 349 |
# 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.(:class => /save/) reload! end |
#update_grades(new_grades) ⇒ Stellar::Gradebook::Student
Changes some of the student’s grades.
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
# 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.(:class => /save/) reload! end |