Class: Classes

Inherits:
Element show all
Defined in:
lib/Appolo/Models/main_model/classes.rb

Constant Summary collapse

'classes'

Instance Attribute Summary collapse

Attributes inherited from Element

#id, #links, #short_name

Instance Method Summary collapse

Constructor Details

#initialize(json_info) ⇒ Classes

Initiate an instance of Classes based upon +json_info* that can be an hash or a JSON string.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/Appolo/Models/main_model/classes.rb', line 21

def initialize(json_info)
  json_data = ModelUtils::check_json_info json_info

  super(json_data[ModelUtils::ID], 
        json_data[ModelUtils::CLASS_NAME], 
        json_data[ModelUtils::LINKS], 
        @@type_of_links)
  
  @full_name = json_data[ModelUtils::FULL_NAME]
  @course_unit_short_name = json_data[ModelUtils::COURSE_UNIT_SHORT_NAME]
  @main_teacher_short_name = json_data[ModelUtils::MAIN_TEACHER_SHORT_NAME]
  @course_unit_id = json_data[ModelUtils::COURSE_UNIT_ID]
  @lective_semester_id = json_data[ModelUtils::LECTIVE_SEMESTER_ID]
  @main_teacher_id = json_data[ModelUtils::MAIN_TEACHER_ID]
  @max_group_size = json_data[ModelUtils::MAX_GROUP_SIZE]

  #TODO aceder ao Links do super e retirar de la´ o link respectivo
  teacher_self_link = json_data[ModelUtils::LINKS]
  teacher_self_link = teacher_self_link[ModelUtils::MAIN_TEACHER]
  unless teacher_self_link.nil?
    #TODO get the id and check if a request has been made in the past
    teacher_self_response = RestClient.get teacher_self_link
    @main_teacher = Teacher.new teacher_self_response
  end

end

Instance Attribute Details

#course_unit_idObject (readonly)

Returns the value of attribute course_unit_id.



16
17
18
# File 'lib/Appolo/Models/main_model/classes.rb', line 16

def course_unit_id
  @course_unit_id
end

#course_unit_short_nameObject (readonly)

Returns the value of attribute course_unit_short_name.



15
16
17
# File 'lib/Appolo/Models/main_model/classes.rb', line 15

def course_unit_short_name
  @course_unit_short_name
end

#full_nameObject (readonly)

Returns the value of attribute full_name.



15
16
17
# File 'lib/Appolo/Models/main_model/classes.rb', line 15

def full_name
  @full_name
end

#lective_semester_idObject (readonly)

Returns the value of attribute lective_semester_id.



16
17
18
# File 'lib/Appolo/Models/main_model/classes.rb', line 16

def lective_semester_id
  @lective_semester_id
end

#main_teacherObject (readonly)

Returns the value of attribute main_teacher.



15
16
17
# File 'lib/Appolo/Models/main_model/classes.rb', line 15

def main_teacher
  @main_teacher
end

#main_teacher_idObject (readonly)

Returns the value of attribute main_teacher_id.



16
17
18
# File 'lib/Appolo/Models/main_model/classes.rb', line 16

def main_teacher_id
  @main_teacher_id
end

#main_teacher_short_nameObject (readonly)

Returns the value of attribute main_teacher_short_name.



15
16
17
# File 'lib/Appolo/Models/main_model/classes.rb', line 15

def main_teacher_short_name
  @main_teacher_short_name
end

#max_group_sizeObject (readonly)

Returns the value of attribute max_group_size.



16
17
18
# File 'lib/Appolo/Models/main_model/classes.rb', line 16

def max_group_size
  @max_group_size
end

Instance Method Details

#lecturesObject

Returns all the lectures related to this class.



68
69
70
71
72
73
74
75
76
# File 'lib/Appolo/Models/main_model/classes.rb', line 68

def lectures
  response_all_lectures = RestClient.get @links.lectures
  all_lectures = JSON.parse response_all_lectures
  temp = []
  all_lectures['classLectures'].each do |lecture|
    temp.push Lecture.new lecture
  end
  temp
end

#participantsObject

Returns all the students related to this class.



56
57
58
59
60
61
62
63
64
# File 'lib/Appolo/Models/main_model/classes.rb', line 56

def participants
  response_all_participants = RestClient.get @links.participants
  all_participants = JSON.parse response_all_participants
  temp = []
  all_participants['students'].each do |participant|
    temp.push Student.new participant
  end
  temp
end

#resourcesObject

Returns all the resources related to a certain class.



80
81
82
83
84
85
86
87
88
# File 'lib/Appolo/Models/main_model/classes.rb', line 80

def resources
  response_all_resources = RestClient.get @links.resources
  all_resources = JSON.parse response_all_resources
  temp = []
  all_resources['classResources'].each do |resource|
    temp.push Resource.new resource
  end
  temp
end

#to_sObject

Small representation of the Classes object



50
51
52
# File 'lib/Appolo/Models/main_model/classes.rb', line 50

def to_s
  "#{@id} - #{@full_name} - #{@main_teacher_short_name}"
end