From 6da1bacfd5cc893a926083fc1c3c09e4d24102d3 Mon Sep 17 00:00:00 2001 From: Artem Darius Weber Date: Mon, 6 Jan 2025 12:09:54 +0300 Subject: [PATCH] refactor: rename contact_info method to get_first_contact for clarity --- lab2/README.md | 6 +++--- lab2/main.rb | 4 ++-- lab2/person.rb | 4 ++-- lab2/student.rb | 2 +- lab2/student_short.rb | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lab2/README.md b/lab2/README.md index 28fc2bc..fc53891 100644 --- a/lab2/README.md +++ b/lab2/README.md @@ -35,10 +35,10 @@ classDiagram + valid_email() : Boolean <> + git_present() : Boolean + contact_present() : Boolean - + contact_info() : String + + get_first_contact() : String + git=(git : String) : void - - validate_id(id: String) : void - - validate_git(git : String) : void + - validate_id(id: String) : void <> + - validate_git(git : String) : void <> - validate_contact(contact : Contact) : void - valid_git?(git : String) : Boolean - valid_id?(id : String) : Boolean diff --git a/lab2/main.rb b/lab2/main.rb index 4de7f41..f7b3fde 100644 --- a/lab2/main.rb +++ b/lab2/main.rb @@ -7,7 +7,7 @@ require_relative 'binary_search_tree' def test_classes person = Person.new(id: '1', git: 'https://github.com/example', phone: '+798912465', telegram: '@example_user', email: 'test@example.com') - puts "Person Contact Info: #{person.contact_info}" + puts "Person Contact Info: #{person.get_first_contact}" student = Student.new( id: '2', @@ -22,7 +22,7 @@ def test_classes ) puts "Student Full Info: #{student.to_s}" puts "Student Initials: #{student.surname_and_initials}" - puts "Student Contact Info: #{student.contact_info}" + puts "Student Contact Info: #{student.get_first_contact}" student_short = StudentShort.from_student(student) puts "Student Short Info: #{student_short.to_s}" diff --git a/lab2/person.rb b/lab2/person.rb index 22e25da..d31be6c 100644 --- a/lab2/person.rb +++ b/lab2/person.rb @@ -20,8 +20,8 @@ class Person @phone || @telegram || @email end - def contact_info - [@phone, @telegram, @email].compact.join(', ') + def get_first_contact + [@phone, @telegram, @email].compact.first end def self.valid_phone_number?(phone) diff --git a/lab2/student.rb b/lab2/student.rb index 7aac56e..618895e 100644 --- a/lab2/student.rb +++ b/lab2/student.rb @@ -56,7 +56,7 @@ class Student < Person end def get_info - "#{surname_and_initials}, Git: #{@git}, Contact: #{contact_info}, Birth Date: #{@birth_date}" + "#{surname_and_initials}, Git: #{@git}, Contact: #{get_first_contact}, Birth Date: #{@birth_date}" end def surname=(surname) diff --git a/lab2/student_short.rb b/lab2/student_short.rb index 4cc126b..80bc23a 100644 --- a/lab2/student_short.rb +++ b/lab2/student_short.rb @@ -38,7 +38,7 @@ class StudentShort < Person end def to_s - contact_info = contact_info() + contact_info = get_first_contact() "#{@surname_initials}, Contact: #{contact_info}" end