feat: add `get_info` method and protected access to key student info

- Added `get_info` method to return a concise summary of the student, including surname with initials, Git link, and primary contact method.
- Implemented individual methods for retrieving surname with initials, Git link, and contact information separately.
- Protected contact fields from direct modification; fields can now only be updated via `set_contacts`.
- Enhanced string parsing with `from_string` constructor to initialize objects directly from formatted strings.
- Updated main file to test new methods and constructor functionality.
pull/4/head
Artem-Darius Weber 4 months ago
parent 8858731565
commit 611c712b8a

@ -20,6 +20,11 @@ begin
email: 'no-replay@djft.ru'
)
puts student1.get_info
puts "Surname and Initials: #{student1.surname_and_initials}"
puts "Git Info: #{student1.git_info}"
puts "Contact Info: #{student1.contact_info}"
student2 = Student.new(
surname: 'Норакет',
name: 'Норакет',

@ -96,9 +96,28 @@ class Student
"Email: #{@email || 'N/A'} | Git: #{@git || 'N/A'}"
end
def get_info
"#{surname_and_initials}, Git: #{git_info}, Contact: #{contact_info}"
end
def surname_and_initials
"#{@surname} #{name[0]}.#{patronymic[0]}."
end
def git_info
@git
end
def contact_info
return "Phone: #{@phone}" if @phone
return "Telegram: #{@telegram}" if @telegram
return "Email: #{@email}" if @email
'No contact available'
end
private
attr_reader :phone, :telegram, :email
attr_writer :phone, :telegram, :email
end
Loading…
Cancel
Save