Class: Stellar::HomeworkList

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

Overview

Homework listing functionality.

Instance Method Summary collapse

Constructor Details

#initialize(course) ⇒ HomeworkList

Creates a Stellar client scoped to a course’s Homework module.

Parameters:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/stellar/homework.rb', line 9

def initialize(course)
  @course = course
  @client = course.client
  @url = course.navigation['Homework']
  
  page = @client.get_nokogiri @url
  @assignments = page.css('#content a[href*="assignment"]').map { |link|
    name = link.inner_text
    url = URI.join page.url, link['href']
    begin
      Stellar::Homework.new url, name, course
    rescue ArgumentError
      nil
    end
  }.reject(&:nil?)
end

Instance Method Details

#allArray<Stellar::Homework>

All assignments in this course’s homework module.

Returns:



28
29
30
# File 'lib/stellar/homework.rb', line 28

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



36
37
38
# File 'lib/stellar/homework.rb', line 36

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