You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kubsu-sm5-ruby/lab2/main.rb

90 lines
2.8 KiB

require 'date'
require_relative 'contact'
require_relative 'person'
require_relative 'student'
require_relative 'student_short'
require_relative 'student_repository'
require_relative 'binary_search_tree'
def test_classes
contact = Contact.new(phone: '+798912465', telegram: '@example_user', email: 'test@example.com')
puts "Contact Info: #{contact.get_single_contact}"
person = Person.new(id: '1', git: 'https://github.com/example', contact: contact)
puts "Person Contact Info: #{person.contact_info}"
student = Student.new(
id: '2',
git: 'https://github.com/student_example',
contact: contact,
surname: 'Иванов',
name: 'Иван',
patronymic: 'Иванович',
birth_date: Date.new(2000, 5, 15)
)
puts "Student Full Info: #{student.to_s}"
puts "Student Initials: #{student.surname_and_initials}"
puts "Student Contact Info: #{student.contact_info}"
student_short = StudentShort.from_student(student)
puts "Student Short Info: #{student_short.to_s}"
file_path = 'students.txt'
students = StudentRepository.read_from_txt(file_path)
puts "Read Students from File:"
students.each { |s| puts s.to_s }
output_path = 'output_students.txt'
StudentRepository.write_to_txt(output_path, students)
puts "Students written to file: #{output_path}"
end
def test_parsing
student_string = 'Иванов Иван Иванович | ID: 3 | Phone: +79876543210 | Telegram: @ivan_user | Email: ivan@example.com | Git: https://github.com/ivanov | Birth Date: 2001-01-01'
student = Student.from_string(student_string)
puts "Parsed Student: #{student.to_s}"
short_string = 'Иванов И.И., Git: https://github.com/ivanov, Contact: Phone: +79876543210'
student_short = StudentShort.from_string('4', short_string)
puts "Parsed StudentShort: #{student_short.to_s}"
end
def test_binary_search_tree
bst = BinarySearchTree.new
student1 = Student.new(
id: '1',
git: 'https://github.com/student1',
contact: Contact.new(phone: '+123456789', telegram: '@student1', email: 'student1@example.com'),
surname: 'Смирнов',
name: 'Алексей',
patronymic: 'Иванович',
birth_date: Date.new(1999, 2, 15)
)
student2 = Student.new(
id: '2',
git: 'https://github.com/student2',
contact: Contact.new(phone: '+987654321', telegram: '@student2', email: 'student2@example.com'),
surname: 'Иванов',
name: 'Иван',
patronymic: 'Сергеевич',
birth_date: Date.new(2001, 5, 10)
)
bst.add(student1)
bst.add(student2)
puts "Students in BST (sorted by birth_date):"
bst.each { |student| puts student.to_s }
end
if __FILE__ == $0
puts "=== Testing Classes ==="
test_classes
puts "\n=== Testing Parsing ==="
test_parsing
puts "\n=== Testing Binary Search Tree ==="
test_binary_search_tree
end