Class: Stellar::Homework

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

Overview

One assignment in the homework tab.

Defined Under Namespace

Classes: Submission

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page_url, name, course) ⇒ Homework

Creates a Stellar client scoped to an assignment.

Parameters:

  • page_url (URI, String)

    URL to the assignment’s main Stellar page

  • assignment (String)

    name, e.g. “name”

  • the (Course)

    course that issued the 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

#clientObject (readonly)

Generic Stellar client used to make requests.



50
51
52
# File 'lib/stellar/homework.rb', line 50

def client
  @client
end

#courseObject (readonly)

The course that this assignment is for.



47
48
49
# File 'lib/stellar/homework.rb', line 47

def course
  @course
end

#nameObject (readonly)

Assignment name.



44
45
46
# File 'lib/stellar/homework.rb', line 44

def name
  @name
end

Instance Method Details

#submissionsObject

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