Class: Stellar::Course
- Inherits:
-
Object
- Object
- Stellar::Course
- Defined in:
- lib/stellar/courses.rb
Overview
Stellar client scoped to a course.
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
The generic Stellar client used to query the server.
-
#is_admin ⇒ Object
readonly
True if the client has administrative rights for this course.
-
#navigation ⇒ Object
readonly
Maps the text in navigation links to URI objects.
-
#number ⇒ Object
readonly
Official MIT course ID, e.g.
-
#url ⇒ Object
readonly
URL to the course’s main page on Stellar.
Class Method Summary collapse
-
.for(number, year, semester, client) ⇒ Stellar::Course
Creates a scoped Stellar client from a link to the course’s page.
-
.from_link(nokogiri_link, client) ⇒ Stellar::Course
Creates a scoped Stellar client from a link to the course’s page.
Instance Method Summary collapse
-
#gradebook ⇒ Object
Client scoped to the course’s Gradebook module.
-
#homework ⇒ Object
Client scoped to the course’s Homework module.
-
#initialize(client, course_url, course_number) ⇒ Course
constructor
Creates a scoped Stellar client from detailed specifications.
Constructor Details
#initialize(client, course_url, course_number) ⇒ Course
Creates a scoped Stellar client from detailed specifications.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/stellar/courses.rb', line 88 def initialize(client, course_url, course_number) @client = client @url = course_url @number = course_number course_page = @client.get_nokogiri course_url @is_admin = course_page.css('p#toolset').length > 0 = course_page.css('#mainnav') unless .length == 1 raise ArgumentError, "#{course_url} is not a course page" end = Hash[.first.css('a').map do |link| [link.inner_text, URI.join(course_page.url, link['href'])] end] end |
Instance Attribute Details
#client ⇒ Object (readonly)
The generic Stellar client used to query the server.
39 40 41 |
# File 'lib/stellar/courses.rb', line 39 def client @client end |
#is_admin ⇒ Object (readonly)
True if the client has administrative rights for this course.
36 37 38 |
# File 'lib/stellar/courses.rb', line 36 def is_admin @is_admin end |
#navigation ⇒ Object (readonly)
Maps the text in navigation links to URI objects.
Example: navigation => <# URI: …/ >
33 34 35 |
# File 'lib/stellar/courses.rb', line 33 def end |
#number ⇒ Object (readonly)
Official MIT course ID, e.g. “6.006”.
23 24 25 |
# File 'lib/stellar/courses.rb', line 23 def number @number end |
#url ⇒ Object (readonly)
URL to the course’s main page on Stellar.
Example: “stellar.mit.edu/S/course/6/fa11/6.006/”
28 29 30 |
# File 'lib/stellar/courses.rb', line 28 def url @url end |
Class Method Details
.for(number, year, semester, client) ⇒ Stellar::Course
Creates a scoped Stellar client from a link to the course’s page.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/stellar/courses.rb', line 64 def self.for(number, year, semester, client) semester_string = case semester when :fall 'fa' when :spring 'sp' when :summer 'su' when :iap 'ia' end term = "#{semester_string}#{year.to_s[-2..-1]}" major = number.split('.', 2).first url = "/S/course/#{major}/#{term}/#{number}/index.html" return self.new(client, url, number) end |
.from_link(nokogiri_link, client) ⇒ Stellar::Course
Creates a scoped Stellar client from a link to the course’s page.
48 49 50 51 52 53 54 55 56 |
# File 'lib/stellar/courses.rb', line 48 def self.from_link(nokogiri_link, client) number = nokogiri_link.css('span.courseNo').inner_text return nil if number.empty? url = nokogiri_link['href'] return nil unless url.index(number) return nil unless /\/S\/course\// =~ url return self.new(client, url, number) end |
Instance Method Details
#gradebook ⇒ Object
Client scoped to the course’s Gradebook module.
112 113 114 |
# File 'lib/stellar/courses.rb', line 112 def gradebook @gradebook ||= Stellar::Gradebook.new self end |
#homework ⇒ Object
Client scoped to the course’s Homework module.
107 108 109 |
# File 'lib/stellar/courses.rb', line 107 def homework @homework ||= Stellar::HomeworkList.new self end |