Class: Manabu::ClassGroup

Inherits:
Resource show all
Defined in:
lib/manabu/class_group.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) ⇒ ClassGroup

Returns a new instance of ClassGroup.



33
34
35
36
37
# File 'lib/manabu/class_group.rb', line 33

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

Instance Attribute Details

#enrollments_countObject (readonly)

Returns the value of attribute enrollments_count.



30
31
32
# File 'lib/manabu/class_group.rb', line 30

def enrollments_count
  @enrollments_count
end

#facility_idObject (readonly)

Returns the value of attribute facility_id.



30
31
32
# File 'lib/manabu/class_group.rb', line 30

def facility_id
  @facility_id
end

#gradeObject (readonly)

Returns the value of attribute grade.



30
31
32
# File 'lib/manabu/class_group.rb', line 30

def grade
  @grade
end

#homeroomObject (readonly)

Returns the value of attribute homeroom.



30
31
32
# File 'lib/manabu/class_group.rb', line 30

def homeroom
  @homeroom
end

#idObject (readonly)

Returns the value of attribute id.



30
31
32
# File 'lib/manabu/class_group.rb', line 30

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



30
31
32
# File 'lib/manabu/class_group.rb', line 30

def name
  @name
end

#notes_countObject (readonly)

Returns the value of attribute notes_count.



30
31
32
# File 'lib/manabu/class_group.rb', line 30

def notes_count
  @notes_count
end

Instance Method Details

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



66
67
68
69
70
71
72
73
74
# File 'lib/manabu/class_group.rb', line 66

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

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

#enrollmentsObject



58
59
60
61
62
63
64
# File 'lib/manabu/class_group.rb', line 58

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

#fill(**info) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/manabu/class_group.rb', line 39

def fill(**info)
  @id = info.fetch(:id, @id)
  @name = info.fetch(:name, @name)
  @grade = info.fetch(:grade, @grade)
  @homeroom = info.fetch(:homeroom, @homeroom)
  @notes_count = info.fetch(:notes_count, @notes_count)
  @enrollments_count = info.fetch(:enrollments_count, @enrollments_count)
  @facility_id = info.fetch(:facility_id, @facility_id)
  self
end

#studentsObject



50
51
52
53
54
55
56
# File 'lib/manabu/class_group.rb', line 50

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