diff --git a/lab2/README.md b/lab2/README.md index 561d38d..28468bf 100644 --- a/lab2/README.md +++ b/lab2/README.md @@ -5,6 +5,21 @@ ```mermaid classDiagram + class BinarySearchTree { + - root : Node + + add(student : Student) : void + + each(&block) : void + - insert(node : Node, student : Student) : Node + - in_order_traversal(node : Node, &block) : void + } + + class Node { + - student : Student + - left : Node + - right : Node + + Node(student : Student) + } + class Contact { - phone : String? - telegram : String? @@ -39,7 +54,7 @@ classDiagram class StudentShort { - surname_initials : String - - contact : String + - contact : Contact + StudentShort(id : String, git : String, surname_initials : String, contact : Contact) + from_student(student : Student) : StudentShort + from_string(id : String, info_string : String) : StudentShort @@ -50,7 +65,8 @@ classDiagram - surname : String - name : String - patronymic : String - + Student(id : String, git : String, contact : Contact, surname : String, name : String, patronymic : String) + - birth_date : Date + + Student(id : String, git : String, contact : Contact, surname : String, name : String, patronymic : String, birth_date : Date) + from_string(student_string : String) : Student + surname_and_initials() : String + to_s() : String @@ -58,6 +74,8 @@ classDiagram - validate_student() } + BinarySearchTree o-- Node + Node o-- Student Contact <|-- Person Person <|-- Student Person <|-- StudentShort diff --git a/lab2/student.rb b/lab2/student.rb index 3902575..2ca1cb8 100644 --- a/lab2/student.rb +++ b/lab2/student.rb @@ -8,10 +8,10 @@ class Student < Person def initialize(id:, git:, contact:, surname:, name:, patronymic:, birth_date:) super(id: id, git: git, contact: contact) - @surname = surname - @name = name - @patronymic = patronymic - @birth_date = birth_date + self.surname = surname + self.name = name + self.patronymic = patronymic + self.birth_date = birth_date validate_student end @@ -58,6 +58,34 @@ class Student < Person "#{surname_and_initials}, Git: #{@git}, Contact: #{contact_info}, Birth Date: #{@birth_date}" end + def surname=(surname) + raise ArgumentError, 'Surname is required' if surname.nil? || surname.strip.empty? + raise ArgumentError, "Invalid surname format: #{surname}" unless valid_name?(surname) + + @surname = surname + end + + def name=(name) + raise ArgumentError, 'Name is required' if name.nil? || name.strip.empty? + raise ArgumentError, "Invalid name format: #{name}" unless valid_name?(name) + + @name = name + end + + def patronymic=(patronymic) + raise ArgumentError, 'Patronymic is required' if patronymic.nil? || patronymic.strip.empty? + raise ArgumentError, "Invalid patronymic format: #{patronymic}" unless valid_name?(patronymic) + + @patronymic = patronymic + end + + def birth_date=(birth_date) + raise ArgumentError, 'Birth date is required' if birth_date.nil? + raise ArgumentError, "Invalid birth date: #{birth_date}" unless birth_date.is_a?(Date) + + @birth_date = birth_date + end + private def validate_student