Class: StudentShort

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

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
13
# File 'lib/source/student/student_short.rb', line 7

def initialize(student)
  @id = student.id
  @surname = student.surname
  @short_name = "#{student.first_name[0]}. #{student.middle_name[0]}."
  @git = student.git unless student.git.nil?
  @contact = student.set_contacts(phone_number: student.phone_number, mail:student.mail,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

#short_name ⇒ Object (readonly)

Returns the value of attribute short_name.



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

def short_name
  @short_name
end

#surname ⇒ Object (readonly)

Returns the value of attribute surname.



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

def surname
  @surname
end

Class Method Details

.from_str(id, str) ⇒ Object



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

def self.from_str(id,str)
  res = JSON.parse(str)

  Student_Short.new(Student.new(first_name: res['fisrst_name'],
                                middle_name:res['middle_name'], surname:res['surname'], id:id,
                                phone_number: result['phone_number'], git: result['git'],
                                mail: result['mail'],telegram: result['telegram']))
end

Instance Method Details

#exist_contact? ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/source/student/student_short.rb', line 45

def exist_contact?
  !(self.phone_number.nil? and self.telegram.nil? and self.mail.nil?)
end

#exist_git? ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/source/student/student_short.rb', line 41

def exist_git?
  !self.git.nil?
end

#short_name_initials ⇒ Object



32
33
34
# File 'lib/source/student/student_short.rb', line 32

def short_name_initials
  "#{@surname} #{@short_name}"
end

#to_s ⇒ Object



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

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

#validate? ⇒ Boolean

валидатор

Returns:

  • (Boolean)


37
38
39
# File 'lib/source/student/student_short.rb', line 37

def validate?
  exist_git? and exist_contact?
end