Skip to content

Commit

Permalink
Fixed some department bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
gterrono committed Mar 3, 2013
1 parent efe8120 commit 2e4c1e9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ examples.rb
json_responses.txt

*.swp
token.rb
helper.rb
test
2 changes: 1 addition & 1 deletion lib/pcr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/pcr/coursehistory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def average(metric)
end
end
end

return -1 if num == 0

# Return average value across all sections
total / num
Expand Down
9 changes: 6 additions & 3 deletions lib/pcr/department.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2e4c1e9

Please sign in to comment.