Class: Section

Inherits:
PCR
  • Object
show all
Defined in:
lib/classes/section.rb

Overview

Section is an individual class under the umbrella of a general Course

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#aliasesObject

Returns the value of attribute aliases.



3
4
5
# File 'lib/classes/section.rb', line 3

def aliases
  @aliases
end

#commentsObject

Returns the value of attribute comments.



3
4
5
# File 'lib/classes/section.rb', line 3

def comments
  @comments
end

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/classes/section.rb', line 3

def description
  @description
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/classes/section.rb', line 3

def id
  @id
end

#instructorsObject

Returns the value of attribute instructors.



3
4
5
# File 'lib/classes/section.rb', line 3

def instructors
  @instructors
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/classes/section.rb', line 3

def name
  @name
end

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/classes/section.rb', line 3

def path
  @path
end

#ratingsObject

Returns the value of attribute ratings.



3
4
5
# File 'lib/classes/section.rb', line 3

def ratings
  @ratings
end

#reviewsObject

Returns the value of attribute reviews.



3
4
5
# File 'lib/classes/section.rb', line 3

def reviews
  @reviews
end

#semesterObject

Returns the value of attribute semester.



3
4
5
# File 'lib/classes/section.rb', line 3

def semester
  @semester
end

Instance Method Details

#get_reviewsObject



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 = []
  @ratings = []
  @instructors = []
  json["result"]["values"].each do |a|
    @comments << {a["instructor"]["id"] => a["comments"]}
    @ratings << {a["instructor"]["id"] => a["ratings"]}
    @instructors << a["instructor"]
  end
  @reviews = {"comments" => @comments, "ratings" => @ratings}
end

#hit_apiObject



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