Class: StudentShort
- Inherits:
-
StudentBase
- Object
- StudentBase
- StudentShort
- Defined in:
- lib/source/models/student_short.rb
Overview
Модель с краткой информацией о студенте
Instance Attribute Summary collapse
-
#contact ⇒ Object
readonly
Returns the value of attribute contact.
-
#last_name_and_initials ⇒ Object
readonly
Returns the value of attribute last_name_and_initials.
Attributes inherited from StudentBase
Class Method Summary collapse
-
.from_student(student) ⇒ Object
Конструктор из объекта класса Student.
Instance Method Summary collapse
-
#initialize(id, info_str) ⇒ StudentShort
constructor
Стандартный конструктор.
-
#to_s ⇒ Object
Преобразование объекта в строку.
Methods inherited from StudentBase
#has_contacts?, #has_git?, #short_contact, #valid?, valid_email?, valid_name?, valid_phone?, valid_profile_name?
Constructor Details
#initialize(id, info_str) ⇒ StudentShort
Стандартный конструктор. Принимает: id - Числовой id студента info_str - JSON строка с полями last_name_and_initials (обязательно), contact, git, а также полями базового класса
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/source/models/student_short.rb', line 31 def initialize(id, info_str) params = JSON.parse(info_str, { symbolize_names: true }) raise ArgumentError, 'Fields required: last_name_and_initials' if !params.key?(:last_name_and_initials) || params[:last_name_and_initials].nil? self.id = id self.last_name_and_initials = params[:last_name_and_initials] self.contact = params[:contact] self.git = params[:git] = {} [:id] = id [:git] = git [contact[:type].to_sym] = contact[:value] if contact super(**) end |
Instance Attribute Details
#contact ⇒ Object
Returns the value of attribute contact.
15 16 17 |
# File 'lib/source/models/student_short.rb', line 15 def contact @contact end |
#last_name_and_initials ⇒ Object
Returns the value of attribute last_name_and_initials.
15 16 17 |
# File 'lib/source/models/student_short.rb', line 15 def last_name_and_initials @last_name_and_initials end |
Class Method Details
.from_student(student) ⇒ Object
Конструктор из объекта класса Student
20 21 22 23 24 |
# File 'lib/source/models/student_short.rb', line 20 def self.from_student(student) raise ArgumentError, 'Student ID is required' if student.id.nil? StudentShort.new(student.id, student.short_info) end |
Instance Method Details
#to_s ⇒ Object
Преобразование объекта в строку
50 51 52 53 54 55 56 57 |
# File 'lib/source/models/student_short.rb', line 50 def to_s result = last_name_and_initials %i[id contact git].each do |attr| attr_val = send(attr) result += ", #{attr}=#{attr_val}" unless attr_val.nil? end result end |