class Manabu::ClassGroup

Attributes

enrollments_count[R]
facility_id[R]
grade[R]
homeroom[R]
id[R]
name[R]
notes_count[R]

Public Class Methods

new(client, **info) click to toggle source
Calls superclass method
# File lib/manabu/class_group.rb, line 33
def initialize(client, **info)
  super
  @students = []
  @enrollments = []
end

Public Instance Methods

add_student(student, args = {}) click to toggle source
# 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
enrollments() click to toggle source
# File lib/manabu/class_group.rb, line 58
def enrollments
  if @enrollments.any?
    @enrollments
  else
    @enrollments = _fetch_enrollments
  end
end
fill(**info) click to toggle source
# 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
students() click to toggle source
# File lib/manabu/class_group.rb, line 50
def students
  if @students.any?
    @students
  else
    @students = _fetch_students
  end
end

Private Instance Methods

_fetch_enrollments() click to toggle source
# File lib/manabu/class_group.rb, line 85
def _fetch_enrollments
  response = @client.get("class_groups/#{id}/enrollments")
  response[:enrollments].map do |enrollment|
    Enrollment.new(@client, enrollment)
  end
end
_fetch_students() click to toggle source
# File lib/manabu/class_group.rb, line 78
def _fetch_students
  response = @client.get("class_groups/#{id}/students")
  response[:students].map do |student|
    Manabu::Student.new(@client, student)
  end
end