Class: Course
Instance Attribute Summary collapse
-
#aliases ⇒ Object
Returns the value of attribute aliases.
-
#credits ⇒ Object
Returns the value of attribute credits.
-
#description ⇒ Object
Returns the value of attribute description.
-
#history ⇒ Object
Returns the value of attribute history.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#retrieved ⇒ Object
Returns the value of attribute retrieved.
-
#reviews ⇒ Object
Returns the value of attribute reviews.
-
#sections ⇒ Object
Returns the value of attribute sections.
-
#semester ⇒ Object
Returns the value of attribute semester.
-
#valid ⇒ Object
Returns the value of attribute valid.
-
#version ⇒ Object
Returns the value of attribute version.
Attributes inherited from PCR
Instance Method Summary collapse
- #average(metric) ⇒ Object
- #compareSemester(other) ⇒ Object
-
#initialize(path, semester, api_endpt, token) ⇒ Course
constructor
A new instance of Course.
Methods inherited from PCR
Constructor Details
#initialize(path, semester, api_endpt, token) ⇒ Course
Returns a new instance of Course.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/classes/course.rb', line 6 def initialize(path, semester, api_endpt, token) @path, @semester = path, semester @api_endpt, @token = api_endpt, token # Hit api api_url = makeURL(self.path) json = JSON.parse(open(api_url).read) # List of sections section_list = json['result']['sections']['values'] @sections = [] section_list.each do |section| @sections << Section.new(section['path'], @api_endpt, @token) end # Assign attrs attrs = %w(aliases credits description history id name reviews retrieved valid version) attrs.each do |attr| if json['result'][attr] self.instance_variable_set("@#{attr}", json['result'][attr]) else self.instance_variable_set("@#{attr}", json[attr]) end end end |
Instance Attribute Details
#aliases ⇒ Object
Returns the value of attribute aliases.
2 3 4 |
# File 'lib/classes/course.rb', line 2 def aliases @aliases end |
#credits ⇒ Object
Returns the value of attribute credits.
2 3 4 |
# File 'lib/classes/course.rb', line 2 def credits @credits end |
#description ⇒ Object
Returns the value of attribute description.
2 3 4 |
# File 'lib/classes/course.rb', line 2 def description @description end |
#history ⇒ Object
Returns the value of attribute history.
2 3 4 |
# File 'lib/classes/course.rb', line 2 def history @history end |
#id ⇒ Object
Returns the value of attribute id.
2 3 4 |
# File 'lib/classes/course.rb', line 2 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/classes/course.rb', line 2 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
2 3 4 |
# File 'lib/classes/course.rb', line 2 def path @path end |
#retrieved ⇒ Object
Returns the value of attribute retrieved.
2 3 4 |
# File 'lib/classes/course.rb', line 2 def retrieved @retrieved end |
#reviews ⇒ Object
Returns the value of attribute reviews.
2 3 4 |
# File 'lib/classes/course.rb', line 2 def reviews @reviews end |
#sections ⇒ Object
Returns the value of attribute sections.
2 3 4 |
# File 'lib/classes/course.rb', line 2 def sections @sections end |
#semester ⇒ Object
Returns the value of attribute semester.
2 3 4 |
# File 'lib/classes/course.rb', line 2 def semester @semester end |
#valid ⇒ Object
Returns the value of attribute valid.
2 3 4 |
# File 'lib/classes/course.rb', line 2 def valid @valid end |
#version ⇒ Object
Returns the value of attribute version.
2 3 4 |
# File 'lib/classes/course.rb', line 2 def version @version end |
Instance Method Details
#average(metric) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/classes/course.rb', line 54 def average(metric) # Aggregate ratings across all sections total, num = 0, 0 self.sections.each do |section| section.reviews.each do |review| total += review.send(metric).to_f num += 1 end end # Return average value across all sections (total / num) end |
#compareSemester(other) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/classes/course.rb', line 33 def compareSemester(other) year = self.semester[0..3] season = self.semester[4] compYear = other.semester[0..3] compSeason = other.semester[4] if year.to_i > compYear.to_i #Later year return 1 elsif year.to_i < compYear.to_i #Earlier year return -1 elsif year.to_i == compYear.to_i #Same year, so test season if season > compSeason #Season is later return 1 elsif season = compSeason #Exact same time return 0 elsif season < compSeason #compSeason is later return -1 end end end |