diff --git a/lab2/main.rb b/lab2/main.rb index c8863aa..4de7f41 100644 --- a/lab2/main.rb +++ b/lab2/main.rb @@ -42,7 +42,7 @@ def test_parsing student = Student.from_string(student_string) puts "Parsed Student: #{student.to_s}" - short_string = 'Иванов И.И., Git: https://github.com/ivanov, Contact: Phone: +79876543210' + short_string = 'Иванов И.И., Contact: Phone: +79876543210' student_short = StudentShort.from_string('4', short_string) puts "Parsed StudentShort: #{student_short.to_s}" end diff --git a/lab2/person.rb b/lab2/person.rb index 6b9700f..22e25da 100644 --- a/lab2/person.rb +++ b/lab2/person.rb @@ -1,7 +1,7 @@ class Person attr_reader :id, :git, :phone, :telegram, :email - def initialize(id:, git:, phone: nil, telegram: nil, email: nil) + def initialize(id:, git: nil, phone: nil, telegram: nil, email: nil) self.class.validate_id(id) self.phone = phone self.telegram = telegram @@ -21,11 +21,7 @@ class Person end def contact_info - return "Phone: #{@phone}" if @phone - return "Telegram: #{@telegram}" if @telegram - return "Email: #{@email}" if @email - - 'No contact available' + [@phone, @telegram, @email].compact.join(', ') end def self.valid_phone_number?(phone) diff --git a/lab2/student_short.rb b/lab2/student_short.rb index 5f950f0..e5d176b 100644 --- a/lab2/student_short.rb +++ b/lab2/student_short.rb @@ -3,15 +3,14 @@ require_relative 'person' class StudentShort < Person attr_reader :surname_initials - def initialize(id:, git:, surname_initials:, phone: nil, telegram: nil, email: nil) - super(id: id, git: git, phone: phone, telegram: telegram, email: email) + def initialize(id:, surname_initials:, phone: nil, telegram: nil, email: nil) + super(id: id, phone: phone, telegram: telegram, email: email) @surname_initials = surname_initials end def self.from_student(student) new( id: student.id, - git: student.git, surname_initials: student.surname_and_initials, phone: student.phone, telegram: student.telegram, @@ -21,17 +20,15 @@ class StudentShort < Person def self.from_string(id, info_string) parts = info_string.split(',').map(&:strip) - raise ArgumentError, 'Invalid info string format' if parts.size < 3 + raise ArgumentError, 'Invalid info string format' if parts.size < 2 surname_initials = parts[0] - git = parts[1].split(': ').last.strip - contact_string = parts[2].split(': ', 2).last.strip + contact_string = parts[1].split(': ', 2).last.strip phone, telegram, email = parse_contact_string(contact_string) new( id: id, - git: git, surname_initials: surname_initials, phone: phone, telegram: telegram, @@ -41,7 +38,7 @@ class StudentShort < Person def to_s contact_info = contact_info() - "#{@surname_initials}, Git: #{@git}, Contact: #{contact_info}" + "#{@surname_initials}, Contact: #{contact_info}" end private