class Stellar::Course

Stellar client scoped to a course.

Attributes

client[R]

The generic Stellar client used to query the server.

is_admin[R]

True if the client has administrative rights for this course.

navigation[R]

Maps the text in navigation links to URI objects.

Example: navigation => <# URI: …/ >

number[R]

Official MIT course ID, e.g. “6.006”.

url[R]

URL to the course's main page on Stellar.

Example: “stellar.mit.edu/S/course/6/fa11/6.006/”

Public Class Methods

for(number, year, semester, client) click to toggle source

Creates a scoped Stellar client from a link to the course's page.

@param [String] number the official MIT course ID, e.g. “6.006” @param [Fixnum] year the year the course was taught e.g. 2011 @param [Symbol] semester :fall, :iap, :spring, :summer @return [Stellar::Course] client scoped to the course

# 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
new(client, course_url, course_number) click to toggle source

Creates a scoped Stellar client from detailed specifications.

@param [Stellar::Client] client generic Stellar client @param [String] course_url HTTP URI to the course's main Stellar page @param [String] course_number official course ID, e.g. “6.006” @raise ArgumentError if the course URL does not point to a course page

# 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
  
  navbar_elems = course_page.css('#mainnav')
  unless navbar_elems.length == 1
    raise ArgumentError, "#{course_url} is not a course page"
  end
  @navigation = Hash[navbar_elems.first.css('a').map do |link|
    [link.inner_text.strip, URI.join(course_page.url, link['href'])]
  end]
end

Public Instance Methods

gradebook() click to toggle source

Client scoped to the course's Gradebook module.

# File lib/stellar/courses.rb, line 112
def gradebook
  @gradebook ||= Stellar::Gradebook.new self
end
homework() click to toggle source

Client scoped to the course's Homework module.

# File lib/stellar/courses.rb, line 107
def homework
  @homework ||= Stellar::HomeworkList.new self
end
members() click to toggle source

Client scoped to the course's Members module.

# File lib/stellar/courses.rb, line 117
def members
  @members ||= Stellar::Members.new self
end