Class: ShnaiderCode::StudentShort

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

Instance Attribute Summary

Attributes inherited from AbstractStudent

#firstname, #id, #lastname, #patronymic

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractStudent

#as_json, #to_s

Constructor Details

#initialize(id:, fio:, git:, email:) ⇒ StudentShort

Returns a new instance of StudentShort.



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

def initialize(id:, fio:, git:, email:)
    fio_components = fio.split(" ")

    self.id = id
    self.firstname = fio_components[0]
    self.lastname = fio_components[1]
    self.patronymic = fio_components[2]

    self.git = git
    self.email = email
end

Class Method Details

.from_string(id, info) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/source/student/student_short.rb', line 32

def self.from_string(id, info) 
    params = info
    .split(";")
    .map { |x| x.split(":") }
    .map { |x| [x[0].to_sym, x[1]] }
    .to_h

    StudentShort.new(
        id: id, 
        fio: params[:fio],
        git: params[:git],
        email: params[:email]
    )
end

.from_student(student) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/source/student/student_short.rb', line 23

def self.from_student(student) 
    StudentShort.new(
        id: student.id, 
        fio: "#{student.firstname} #{student.lastname} #{student.patronymic}",
        git: student.git,
        email: student.email
    )
end

Instance Method Details

#contacts_infoObject



51
52
53
# File 'lib/source/student/student_short.rb', line 51

def contacts_info
    "git:#{git};email:#{email}"
end

#fio_infoObject



47
48
49
# File 'lib/source/student/student_short.rb', line 47

def fio_info
    "fio:#{firstname} #{lastname.upcase[0]} #{patronymic.upcase[0]}"
end

#get_infoObject



55
56
57
# File 'lib/source/student/student_short.rb', line 55

def get_info
    [fio_info, contacts_info].join(";")
end