require_relative 'person' class StudentShort < Person attr_reader :surname_initials, :contact def initialize(id:, git:, surname_initials:, contact:) super(id: id, git: git, contact: contact) @surname_initials = surname_initials end def self.from_student(student) new( id: student.id, git: student.git, surname_initials: student.surname_and_initials, contact: student.contact ) end def self.from_string(id, info_string) parts = info_string.split(',').map(&:strip) raise ArgumentError, 'Invalid info string format' if parts.size < 3 surname_initials = parts[0] git = parts[1].split(': ').last.strip contact_string = parts[2].split(': ', 2).last.strip contact = Contact.new_from_info(contact_string) new( id: id, git: git, surname_initials: surname_initials, contact: contact ) end def to_s "#{@surname_initials}, Git: #{@git}, Contact: #{@contact}" end end