Class: StudentShort

Inherits:
Object
  • Object
show all
Defined in:
lib/source/student/student_short.rb

Overview

(last_name, first_name, paternal_name, id:nil, phone:nil, git:nil, telegram:nil, email:nil)

Direct Known Subclasses

Student

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(student) ⇒ StudentShort

Returns a new instance of StudentShort.



7
8
9
10
11
12
# File 'lib/source/student/student_short.rb', line 7

def initialize(student)
  @id = student.id
  @initials = "#{student.last_name} #{student.first_name[0]}.#{student.paternal_name[0]}. "
  @git = student.git unless student.git.nil?
  @contact = student.set_contacts(phone: student.phone, email: student.email, telegram: student.telegram)
end

Instance Attribute Details

#contact ⇒ Object (readonly)

Returns the value of attribute contact.



5
6
7
# File 'lib/source/student/student_short.rb', line 5

def contact
  @contact
end

#git ⇒ Object (readonly)

Returns the value of attribute git.



5
6
7
# File 'lib/source/student/student_short.rb', line 5

def git
  @git
end

#id ⇒ Object (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/source/student/student_short.rb', line 5

def id
  @id
end

#initials ⇒ Object (readonly)

Returns the value of attribute initials.



5
6
7
# File 'lib/source/student/student_short.rb', line 5

def initials
  @initials
end

Class Method Details

.from_str(id, str) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
# File 'lib/source/student/student_short.rb', line 14

def self.from_str(id, str)
  result = JSON.parse(str)
  raise ArgumentError, 'Missing fields: last_name, first_name, paternal_name' unless result.key?('first_name') &&
    result.key?('last_name') && result.key?('paternal_name')

  StudentShort.new(Student.new(last_name: result['last_name'],first_name: result['first_name'],
                               paternal_name: result['paternal_name'],id: id,
                               phone: result['phone'], git: result['git'],
                               email: result['email'],telegram: result['telegram']))
end

Instance Method Details

#shortName ⇒ Object



25
26
27
# File 'lib/source/student/student_short.rb', line 25

def shortName
  "#{@initials}"
end

#to_s ⇒ Object



28
29
30
31
32
33
34
# File 'lib/source/student/student_short.rb', line 28

def to_s
  res = "#{initials}"
  res += "id=#{id}" unless id.nil?
  res += " git=#{git}" unless git.nil?
  res += " #{contact}" unless contact.nil?
  res
end