Class: Stellar::Homework
- Inherits:
-
Object
- Object
- Stellar::Homework
- Defined in:
- lib/stellar/homework.rb
Overview
One assignment in the homework tab.
Defined Under Namespace
Classes: Submission
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Generic Stellar client used to make requests.
-
#course ⇒ Object
readonly
The course that this assignment is for.
-
#name ⇒ Object
readonly
Assignment name.
Instance Method Summary collapse
-
#initialize(page_url, name, course) ⇒ Homework
constructor
Creates a Stellar client scoped to an assignment.
-
#submissions ⇒ Object
List of submissions associated with this problem set.
Constructor Details
#initialize(page_url, name, course) ⇒ Homework
Creates a Stellar client scoped to an assignment.
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/stellar/homework.rb', line 57 def initialize(page_url, name, course) @name = name @url = page_url @course = course @client = course.client page = @client.get_nokogiri @url unless page.css('#content p b').any? { |dom| dom.inner_text.strip == name } raise ArgumentError, 'Invalid homework page URL' end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Generic Stellar client used to make requests.
50 51 52 |
# File 'lib/stellar/homework.rb', line 50 def client @client end |
#course ⇒ Object (readonly)
The course that this assignment is for.
47 48 49 |
# File 'lib/stellar/homework.rb', line 47 def course @course end |
#name ⇒ Object (readonly)
Assignment name.
44 45 46 |
# File 'lib/stellar/homework.rb', line 44 def name @name end |
Instance Method Details
#submissions ⇒ Object
List of submissions associated with this problem set.
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/stellar/homework.rb', line 70 def submissions page = @client.get_nokogiri @url @submissions ||= page.css('.gradeTable tbody tr').map { |tr| begin Stellar::Homework::Submission.new tr, self rescue ArgumentError nil end }.reject(&:nil?) end |