Class: MyUW::SLNInfo
- Inherits:
-
Object
- Object
- MyUW::SLNInfo
- Defined in:
- lib/myuw/sln.rb
Overview
Synopsis
Gets information regarding a specific SLN, returning information in a SLN object.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#myuw ⇒ Object
Returns the value of attribute myuw.
-
#sln ⇒ Object
Returns the value of attribute sln.
-
#term ⇒ Object
Returns the value of attribute term.
Instance Method Summary collapse
-
#fetch_data ⇒ Object
Fetches the information for the given SLN.
-
#get_course_info(page) ⇒ Object
Gets the basic SLN info (the top table in the current status page).
-
#get_course_notes(page) ⇒ Object
Gets the notes for a course.
-
#get_enrollment_info(page) ⇒ Object
Gets the enrollment information for an SLN such as current enrollment, space available, etc.
-
#get_sln_page ⇒ Object
Gets the SLN info page for the SLN and term, raising an exception if it is requested too soon.
-
#initialize(myuw) ⇒ SLNInfo
constructor
A new instance of SLNInfo.
Constructor Details
#initialize(myuw) ⇒ SLNInfo
Returns a new instance of SLNInfo.
11 12 13 14 15 16 |
# File 'lib/myuw/sln.rb', line 11 def initialize(myuw) @myuw = myuw @term = nil @data = nil @sln = nil end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
9 10 11 |
# File 'lib/myuw/sln.rb', line 9 def data @data end |
#myuw ⇒ Object
Returns the value of attribute myuw.
8 9 10 |
# File 'lib/myuw/sln.rb', line 8 def myuw @myuw end |
#sln ⇒ Object
Returns the value of attribute sln.
7 8 9 |
# File 'lib/myuw/sln.rb', line 7 def sln @sln end |
#term ⇒ Object
Returns the value of attribute term.
6 7 8 |
# File 'lib/myuw/sln.rb', line 6 def term @term end |
Instance Method Details
#fetch_data ⇒ Object
Fetches the information for the given SLN.
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/myuw/sln.rb', line 31 def fetch_data raise ArgumentError.new("SLN not set.") if @sln.nil? raise ArgumentError.new("Term not set.") if @term.nil? raise NotLoggedInError.new("User must be logged in to fetch SLN data") unless @myuw.logged_in? # Request the actual page page = get_sln_page # Get the actual course information get_course_info page get_enrollment_info page get_course_notes page end |
#get_course_info(page) ⇒ Object
Gets the basic SLN info (the top table in the current status page)
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/myuw/sln.rb', line 74 def get_course_info(page) info_nodes = page.search("//table[@border=1 and @cellpadding=3]//tr[@rowspan=1]//td") data_order = [nil, :course, :section, :type, :credits, :title] info_nodes.each_with_index do |node, i| if i < data_order.length then data_key = data_order[i] unless data_key.nil? @data ||= {} @data[data_key] = node.inner_text.strip.gsub("\302\240", "") end end end end |
#get_course_notes(page) ⇒ Object
Gets the notes for a course
109 110 111 112 113 |
# File 'lib/myuw/sln.rb', line 109 def get_course_notes(page) info_nodes = page.search("//table[@border=1 and @cellpadding=3]//tr[count(td)=1]//preceding-sibling::tr[count(th)=1]//following-sibling::tr//td") @data ||= {} @data[:notes] = info_nodes[0].inner_text.strip end |
#get_enrollment_info(page) ⇒ Object
Gets the enrollment information for an SLN such as current enrollment, space available, etc.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/myuw/sln.rb', line 92 def get_enrollment_info(page) info_nodes = page.search("//table[@border=1 and @cellpadding=3]//tr[count(td)=5]//td") data_order = [:current_enrollment, :limit_enrollment, :room_capacity, :space_available, :status] info_nodes.each_with_index do |node, i| if i < data_order.length then data_key = data_order[i] unless data_key.nil? @data ||= {} @data[data_key] = node.inner_text.strip.gsub("\302\240", "") end end end end |
#get_sln_page ⇒ Object
Gets the SLN info page for the SLN and term, raising an exception if it is requested too soon
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/myuw/sln.rb', line 61 def get_sln_page page = @myuw.browser.get("https://sdb.admin.washington.edu/timeschd/uwnetid/sln.asp?QTRYR=#{@term}&SLN=#{@sln}") if page.uri.to_s == "http://www.washington.edu/students/timeschd/badrequest.html" raise RequestSLNTooSoonError.new("Attempted to fetch SLN data too soon.") elsif page.body.to_s =~ /SLN: #{@sln} does not exist./ raise InvalidSLNError.new("SLN does not exist.") end page end |