Class: Stellar::Gradebook::StudentList
- Inherits:
-
Object
- Object
- Stellar::Gradebook::StudentList
- Defined in:
- lib/stellar/gradebook.rb
Overview
Collection of students in a course’s Gradebook module.
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Generic Stellar client used to make requests.
-
#gradebook ⇒ Object
readonly
The course’s.
Instance Method Summary collapse
-
#all ⇒ Array<Stellar::Gradebook::Student>
All students listed in this course’s Gradebook module.
-
#initialize(gradebook) ⇒ StudentList
constructor
Creates a list of students in a class’ Gradebook.
-
#named(name) ⇒ Stellar::Gradebook::Student
A student in the course’s Gradebook module.
-
#reload! ⇒ Stellar::Gradebook::StudentList
Reloads the contents of this student list.
-
#with_email(email) ⇒ Stellar::Gradebook::Student
A student in the course’s Gradebook module.
Constructor Details
#initialize(gradebook) ⇒ StudentList
Creates a list of students in a class’ Gradebook.
190 191 192 193 194 195 196 |
# File 'lib/stellar/gradebook.rb', line 190 def initialize(gradebook) @gradebook = gradebook @client = gradebook.client @url = gradebook.['Students'] reload! end |
Instance Attribute Details
#client ⇒ Object (readonly)
Generic Stellar client used to make requests.
185 186 187 |
# File 'lib/stellar/gradebook.rb', line 185 def client @client end |
#gradebook ⇒ Object (readonly)
The course’s
182 183 184 |
# File 'lib/stellar/gradebook.rb', line 182 def gradebook @gradebook end |
Instance Method Details
#all ⇒ Array<Stellar::Gradebook::Student>
All students listed in this course’s Gradebook module.
200 201 202 |
# File 'lib/stellar/gradebook.rb', line 200 def all @students end |
#named(name) ⇒ Stellar::Gradebook::Student
A student in the course’s Gradebook module.
208 209 210 |
# File 'lib/stellar/gradebook.rb', line 208 def named(name) @students.find { |a| a.name == name } end |
#reload! ⇒ Stellar::Gradebook::StudentList
Reloads the contents of this student list.
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/stellar/gradebook.rb', line 223 def reload! student_page = @client.get_nokogiri @url data_script = student_page.css('script').find do |script| /var rows\s*\=.*\;/m =~ script.inner_text end data = JSON.parse((/var rows\s*\=([^;]*)\;/m). match(data_script.inner_text)[1].gsub("'", '"')) @students = data.map { |student_line| email = student_line[0] url = URI.join @url.to_s, student_line[1] name = student_line[2].split(',', 2).map(&:strip).reverse.join(' ') begin Stellar::Gradebook::Student.new url, email, name, gradebook rescue ArgumentError nil end }.reject(&:nil?) self end |
#with_email(email) ⇒ Stellar::Gradebook::Student
A student in the course’s Gradebook module.
216 217 218 |
# File 'lib/stellar/gradebook.rb', line 216 def with_email(email) @students.find { |a| a.email == email } end |