Class: Stellar::Gradebook::AssignmentList

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

Overview

Collection of assignments in a course’s Gradebook module.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gradebook) ⇒ AssignmentList

Creates a list of Gradebook assignments for a class.

Parameters:



55
56
57
58
59
60
61
# File 'lib/stellar/gradebook.rb', line 55

def initialize(gradebook)
  @gradebook = gradebook
  @client = gradebook.client
  
  @url = gradebook.navigation['Assignments']
  reload!
end

Instance Attribute Details

#clientObject (readonly)

Generic Stellar client used to make requests.



50
51
52
# File 'lib/stellar/gradebook.rb', line 50

def client
  @client
end

#gradebookObject (readonly)

The course’s



47
48
49
# File 'lib/stellar/gradebook.rb', line 47

def gradebook
  @gradebook
end

Instance Method Details

#add(long_name, short_name, max_points, due_on = Time.now, weight = nil) ⇒ Stellar::Gradebook::AssignmentList

Creates a new assignment in the Gradebook.

Parameters:

  • long_name (String)

    the assignment’s full name

  • short_name (String)

    a shorter name?

  • max_score (Numeric)

    maximum score that a student can receive

  • due_on (Time) (defaults to: Time.now)

    date when the pset is due

  • weight (Numeric) (defaults to: nil)

    score weight in total score for the course

Returns:



103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/stellar/gradebook.rb', line 103

def add(long_name, short_name, max_points, due_on = Time.now, weight = nil)
  add_page = @client.get @gradebook.navigation['Add Assignment']
  add_form = add_page.form_with :action => /new/i
  add_form.field_with(:name => /title/i).value = long_name
  add_form.field_with(:name => /short/i).value = short_name
  add_form.field_with(:name => /points/i).value = max_points.to_s
  add_form.field_with(:name => /short/i).value = due_on.strftime('%m.%d.%Y')
  if weight
    add_form.field_with(:name => /weight/i).value = weight.to_s
  end
  add_form.submit add_form.button_with(:class => /active/)
  
  reload!
end

#allArray<Stellar::Gradebook::Assignment>

All assignments in this course’s Gradebook module.

Returns:



66
67
68
# File 'lib/stellar/gradebook.rb', line 66

def all
  @assignments
end

#named(name) ⇒ Stellar::Homework

An assignment in the course’s homework module.

Parameters:

  • name (String)

    the name of the desired assignment

Returns:

  • (Stellar::Homework)

    an assignment with the given name, or nil if no such assignment exists



74
75
76
# File 'lib/stellar/gradebook.rb', line 74

def named(name)
  @assignments.find { |a| a.name == name }
end

#reload!Stellar::Gradebook::AssignmentList

Reloads the contents of this assignment list.

Returns:



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/stellar/gradebook.rb', line 81

def reload!
  assignment_page = @client.get_nokogiri @url
  
  @assignments = assignment_page.css('.gradeTable tbody tr').map { |tr|
    begin
      Stellar::Gradebook::Assignment.new tr, self
    rescue ArgumentError
      nil
    end
  }.reject(&:nil?)
  
  self
end