Class: Section
Overview
Section is an individual class under the umbrella of a general Course
Instance Attribute Summary collapse
-
#aliases ⇒ Object
Returns the value of attribute aliases.
-
#comments ⇒ Object
Returns the value of attribute comments.
-
#description ⇒ Object
Returns the value of attribute description.
-
#id ⇒ Object
Returns the value of attribute id.
-
#instructors ⇒ Object
Returns the value of attribute instructors.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#ratings ⇒ Object
Returns the value of attribute ratings.
-
#reviews ⇒ Object
Returns the value of attribute reviews.
-
#semester ⇒ Object
Returns the value of attribute semester.
Instance Method Summary collapse
- #get_reviews ⇒ Object
- #hit_api ⇒ Object
-
#initialize(id, hit_api = true) ⇒ Section
constructor
A new instance of Section.
Methods inherited from PCR
#course, #instructor, #section
Constructor Details
#initialize(id, hit_api = true) ⇒ Section
Returns a new instance of Section.
5 6 7 8 9 10 11 12 |
# File 'lib/classes/section.rb', line 5 def initialize(id, hit_api = true) # Set instance vars @id = id # Hit api to fill additional info self.hit_api() unless hit_api == false end |
Instance Attribute Details
#aliases ⇒ Object
Returns the value of attribute aliases.
3 4 5 |
# File 'lib/classes/section.rb', line 3 def aliases @aliases end |
#comments ⇒ Object
Returns the value of attribute comments.
3 4 5 |
# File 'lib/classes/section.rb', line 3 def comments @comments end |
#description ⇒ Object
Returns the value of attribute description.
3 4 5 |
# File 'lib/classes/section.rb', line 3 def description @description end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/classes/section.rb', line 3 def id @id end |
#instructors ⇒ Object
Returns the value of attribute instructors.
3 4 5 |
# File 'lib/classes/section.rb', line 3 def instructors @instructors end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/classes/section.rb', line 3 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/classes/section.rb', line 3 def path @path end |
#ratings ⇒ Object
Returns the value of attribute ratings.
3 4 5 |
# File 'lib/classes/section.rb', line 3 def end |
#reviews ⇒ Object
Returns the value of attribute reviews.
3 4 5 |
# File 'lib/classes/section.rb', line 3 def reviews @reviews end |
#semester ⇒ Object
Returns the value of attribute semester.
3 4 5 |
# File 'lib/classes/section.rb', line 3 def semester @semester end |
Instance Method Details
#get_reviews ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/classes/section.rb', line 39 def get_reviews() api_url = @@api_endpt + "courses/" + self.id.to_s + "/reviews?token=" + @@token json = JSON.parse(open(api_url).read) @comments = [] = [] @instructors = [] json["result"]["values"].each do |a| @comments << {a["instructor"]["id"] => a["comments"]} << {a["instructor"]["id"] => a["ratings"]} @instructors << a["instructor"] end @reviews = {"comments" => @comments, "ratings" => } end |
#hit_api ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/classes/section.rb', line 14 def hit_api() data = ["aliases", "name", "path", "semester", "description"] api_url = @@api_endpt + "courses/" + self.id.to_s + "?token=" + @@token json = JSON.parse(open(api_url).read) data.each do |d| case d when "aliases" self.instance_variable_set("@#{d}", json["result"]["aliases"]) when "name" self.instance_variable_set("@#{d}", json["result"]["name"]) when "path" self.instance_variable_set("@#{d}", json["result"]["path"]) when "semester" self.instance_variable_set("@#{d}", json["result"]["semester"]) when "description" self.instance_variable_set("@#{d}", json["result"]["description"]) end end # Get review data self.get_reviews end |