lib/source/models/student_short.rb in shnaider_code-1.1.5 vs lib/source/models/student_short.rb in shnaider_code-1.1.6

- old
+ new

@@ -1,35 +1,29 @@ # frozen_string_literal: true -## -# Модель с краткой информацией о студенте - class StudentShort < StudentBase + # Делаем new предка публичным public_class_method :new + # Стандартные геттеры и сеттеры + private attr_writer :last_name_and_initials, :contact public attr_reader :last_name_and_initials, :contact - ## - # Конструктор из объекта класса Student - + # Конструктор из Student def self.from_student(student) raise ArgumentError, 'Student ID is required' if student.id.nil? StudentShort.new(student.id, student.short_info) end - ## - # Стандартный конструктор. Принимает: - # id - Числовой id студента - # info_str - JSON строка с полями last_name_and_initials (обязательно), contact, git, а также полями базового класса - + # Стандартный конструктор 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 @@ -42,12 +36,10 @@ options[:git] = git options[contact[:type].to_sym] = contact[:value] if contact super(**options) end - ## - # Преобразование объекта в строку - + # Методы приведения объекта к строке 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?