Class: Manabu::Course

Inherits:
Resource show all
Defined in:
lib/manabu/course.rb

Defined Under Namespace

Classes: Enrollment

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#_fill, #to_hash

Constructor Details

#initialize(client, **info) ⇒ Course

Returns a new instance of Course.



43
44
45
46
47
# File 'lib/manabu/course.rb', line 43

def initialize(client, **info)
  super
  @students = []
  @enrollments = []
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



40
41
42
# File 'lib/manabu/course.rb', line 40

def code
  @code
end

#enrollments_countObject (readonly)

Returns the value of attribute enrollments_count.



40
41
42
# File 'lib/manabu/course.rb', line 40

def enrollments_count
  @enrollments_count
end

#facility_idObject (readonly)

Returns the value of attribute facility_id.



40
41
42
# File 'lib/manabu/course.rb', line 40

def facility_id
  @facility_id
end

#idObject (readonly)

Returns the value of attribute id.



40
41
42
# File 'lib/manabu/course.rb', line 40

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



40
41
42
# File 'lib/manabu/course.rb', line 40

def name
  @name
end

#notes_countObject (readonly)

Returns the value of attribute notes_count.



40
41
42
# File 'lib/manabu/course.rb', line 40

def notes_count
  @notes_count
end

#students_countObject (readonly)

Returns the value of attribute students_count.



40
41
42
# File 'lib/manabu/course.rb', line 40

def students_count
  @students_count
end

#syllbaus_idObject (readonly)

Returns the value of attribute syllbaus_id.



40
41
42
# File 'lib/manabu/course.rb', line 40

def syllbaus_id
  @syllbaus_id
end

Instance Method Details

#add_student(student, args = {}) ⇒ Object



77
78
79
80
81
82
83
84
85
86
# File 'lib/manabu/course.rb', line 77

def add_student(student, args = {})
  response = @client.post("courses/#{id}/enrollments",
    student_id: student.id,
    seat_number: args[:seat_number]
  )

  Enrollment.new(@client, response).tap do |enrollment|
    @enrollments << enrollment
  end
end

#enrollmentsObject



69
70
71
72
73
74
75
# File 'lib/manabu/course.rb', line 69

def enrollments
  if @enrollments.any?
    @enrollments
  else
    @enrollments = _fetch_enrollments
  end
end

#fill(**info) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/manabu/course.rb', line 49

def fill(**info)
  @id = info.fetch(:id, @id)
  @name = info.fetch(:name, @name)
  @code = info.fetch(:code, @code)
  @notes_count = info.fetch(:notes_count, @notes_count)
  @students_count = info.fetch(:students_count, @students_count)
  @enrollments_count = info.fetch(:enrollments_count, @enrollments_count)
  @facility_id = info.fetch(:facility_id, @facility_id)
  @syllabus_id = info.fetch(:syllabus_id, @syllabus_id)
  self
end

#studentsObject



61
62
63
64
65
66
67
# File 'lib/manabu/course.rb', line 61

def students
  if @students.any?
    @students
  else
    @students = _fetch_students
  end
end