feat: Add read_from_txt method to Student class

- Introduced read_from_txt method in Student class to read student data from a text file.
pull/4/head
Artem-Darius Weber 4 months ago
parent d387e12d7d
commit acf69c4385

@ -42,6 +42,26 @@ class Student < Person
)
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]}."
end

Loading…
Cancel
Save