From c1ca0ea8459f1d202d5a0e058ce1e62d7eacc8dd Mon Sep 17 00:00:00 2001 From: Artem Darius Weber Date: Sat, 21 Sep 2024 16:24:24 +0300 Subject: [PATCH] feat: add validation methods for Git link and contact presence - Added `validate` method to ensure each Student object has a Git link and at least one contact method (phone, telegram, or email). - Implemented `git_present?` method to check the presence of a Git link. - Implemented `contact_present?` method to check the presence of at least one contact method. - Modified the constructor to call `validate` during object initialization. --- lab2/student.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lab2/student.rb b/lab2/student.rb index 99d3793..e351eb7 100644 --- a/lab2/student.rb +++ b/lab2/student.rb @@ -46,6 +46,21 @@ class Student @git = args[:git] raise ArgumentError, "Invalid git format: #{@git}" unless Student.valid_git?(@git) + + validate + end + + def git_present? + !@git.nil? && !@git.empty? + end + + def contact_present? + !(@phone.nil? || @phone.empty?) || !(@telegram.nil? || @telegram.empty?) || !(@email.nil? || @email.empty?) + end + + def validate + raise ArgumentError, "Git link is required" unless git_present? + raise ArgumentError, "At least one contact (phone, telegram, or email) is required" unless contact_present? end def to_s