Class: Manabu::Student

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

Defined Under Namespace

Classes: GuardianNotAdded

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#_fill, #initialize, #to_hash

Constructor Details

This class inherits a constructor from Manabu::Resource

Instance Attribute Details

#birth_dateObject

Returns the value of attribute birth_date.



7
8
9
# File 'lib/manabu/student.rb', line 7

def birth_date
  @birth_date
end

#genderObject

Returns the value of attribute gender.



7
8
9
# File 'lib/manabu/student.rb', line 7

def gender
  @gender
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/manabu/student.rb', line 7

def id
  @id
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/manabu/student.rb', line 7

def name
  @name
end

#name_readingObject

Returns the value of attribute name_reading.



7
8
9
# File 'lib/manabu/student.rb', line 7

def name_reading
  @name_reading
end

#surnameObject

Returns the value of attribute surname.



7
8
9
# File 'lib/manabu/student.rb', line 7

def surname
  @surname
end

#surname_readingObject

Returns the value of attribute surname_reading.



7
8
9
# File 'lib/manabu/student.rb', line 7

def surname_reading
  @surname_reading
end

Instance Method Details

#add_guardian(guardian) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/manabu/student.rb', line 27

def add_guardian(guardian)
  # NOTE: detect when guardian is already added to student
  response = @client.post("students/#{id}/student_guardians", guardian_id: guardian.id)
  self
rescue StandardError
  raise GuardianNotAdded, 'Guardian is not added to student'
end

#coursesObject



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

def courses
  response = @client.get("students/#{id}/courses")
  response[:courses].map do |course|
    Manabu::Course.new(@client, course)
  end
end

#fill(**info) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/manabu/student.rb', line 10

def fill(**info)
  @id = info.fetch(:id, @id)
  @surname = info.fetch(:surname, @surname)
  @name = info.fetch(:name, @name)
  @name_reading = info.fetch(:name_reading, @name_reading)
  @surname_reading = info.fetch(:surname_reading, @surname_reading)
  @birth_date = info.fetch(:birth_date, @birth_date)
  @gender = info.fetch(:gender, @gender)

  self
end

#guardiansObject



35
36
37
38
39
40
# File 'lib/manabu/student.rb', line 35

def guardians
  response = @client.get("students/#{id}/guardians")
  response[:guardians].map do |guardian|
    Manabu::Guardian.new(@client, guardian)
  end
end

#set(**info) ⇒ Object



22
23
24
25
# File 'lib/manabu/student.rb', line 22

def set(**info)
  response = @client.patch("students/#{@id}", info)
  fill(response)
end