diff --git a/.gitignore b/.gitignore index 7d46220..95f8985 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,5 @@ examples.rb json_responses.txt *.swp -token.rb +helper.rb +test diff --git a/lib/pcr.rb b/lib/pcr.rb index f15e176..3218356 100644 --- a/lib/pcr.rb +++ b/lib/pcr.rb @@ -27,7 +27,7 @@ def instructor(id) raise NotImplementedError.new("Instructors have not yet been implemented.") end - def dept(code) + def department(code) Department.new code end end diff --git a/lib/pcr/coursehistory.rb b/lib/pcr/coursehistory.rb index 524e0a0..2ea370b 100644 --- a/lib/pcr/coursehistory.rb +++ b/lib/pcr/coursehistory.rb @@ -53,6 +53,8 @@ def average(metric) end end end + + return -1 if num == 0 # Return average value across all sections total / num diff --git a/lib/pcr/department.rb b/lib/pcr/department.rb index 3d0decd..973df02 100644 --- a/lib/pcr/department.rb +++ b/lib/pcr/department.rb @@ -6,7 +6,7 @@ class Department include PCR::Resource attr_reader :name, :coursehistories, :id, :path, :retrieved, :valid, :version - def initialize(course_code) + def initialize(name) @name = name # Read JSON from PCR API @@ -26,8 +26,11 @@ def average(metric) # Aggregate ratings across all coursehistories total, num = 0, 0 coursehistories.each do |c| - total += c.average(metric).to_f - num += 1 + av = c.average(metric).to_f + if av != -1 + total += av + num += 1 + end end # Return average value across all sections