Class: Classes

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

Constant Summary collapse

TYPE =
'classes'

Instance Attribute Summary collapse

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
# File 'lib/Appolo/Models/main_model/classes.rb', line 21

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

  @id = json_data[ModelUtils::ID]
  @full_name = json_data[ModelUtils::FULL_NAME]
  @course_unit_short_name = json_data[ModelUtils::COURSE_UNIT_SHORT_NAME]
  @class_name = json_data[ModelUtils::CLASS_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]

  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

  @links = Links.new(json_data[ModelUtils::LINKS], TYPE)
end

Instance Attribute Details

#class_nameObject (readonly)

Returns the value of attribute class_name


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

def class_name
  @class_name
end

#course_unit_idObject (readonly)

Returns the value of attribute course_unit_id


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

def course_unit_id
  @course_unit_id
end

#course_unit_short_nameObject (readonly)

Returns the value of attribute course_unit_short_name


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

def course_unit_short_name
  @course_unit_short_name
end

#full_nameObject (readonly)

Returns the value of attribute full_name


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

def full_name
  @full_name
end

#idObject (readonly)

Returns the value of attribute id


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

def id
  @id
end

#lective_semester_idObject (readonly)

Returns the value of attribute lective_semester_id


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

def lective_semester_id
  @lective_semester_id
end

Returns the value of attribute links


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

def links
  @links
end

#main_teacherObject (readonly)

Returns the value of attribute main_teacher


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

def main_teacher
  @main_teacher
end

#main_teacher_idObject (readonly)

Returns the value of attribute main_teacher_id


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

def main_teacher_id
  @main_teacher_id
end

#main_teacher_short_nameObject (readonly)

Returns the value of attribute main_teacher_short_name


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

def main_teacher_short_name
  @main_teacher_short_name
end

#max_group_sizeObject (readonly)

Returns the value of attribute max_group_size


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

def max_group_size
  @max_group_size
end

Instance Method Details

#lecturesObject

Returns all the lectures related to this class.


65
66
67
68
69
70
71
72
73
# File 'lib/Appolo/Models/main_model/classes.rb', line 65

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.


53
54
55
56
57
58
59
60
61
# File 'lib/Appolo/Models/main_model/classes.rb', line 53

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.


77
78
79
80
81
82
83
84
85
# File 'lib/Appolo/Models/main_model/classes.rb', line 77

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


47
48
49
# File 'lib/Appolo/Models/main_model/classes.rb', line 47

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