diff --git a/lab2/student.rb b/lab2/student.rb index f0a5121..6d2dd9e 100644 --- a/lab2/student.rb +++ b/lab2/student.rb @@ -41,6 +41,26 @@ class Student < Person git: git ) end + + def self.read_from_txt(file_path) + raise IOError, "File path is invalid or file does not exist: #{file_path}" unless File.exist?(file_path) + + students = [] + + File.foreach(file_path) do |line| + line.strip! + next if line.empty? # Пропустить пустые строки + + begin + student = from_string(line) + students << student + rescue ArgumentError => e + puts "Error processing line: '#{line}'. Reason: #{e.message}" + end + end + + students + end def surname_and_initials "#{@surname} #{name[0]}.#{patronymic[0]}."