From d5f67c2de0de6d26bb547d7185669c95895a39e7 Mon Sep 17 00:00:00 2001 From: Artem Darius Weber Date: Thu, 2 Jan 2025 15:17:12 +0300 Subject: [PATCH] refactor: convert instance validation methods to class methods in Contact class --- lab2/contact.rb | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lab2/contact.rb b/lab2/contact.rb index 056aac4..c5bde96 100644 --- a/lab2/contact.rb +++ b/lab2/contact.rb @@ -29,23 +29,18 @@ class Contact 'No contact available' end - private - - def valid_phone_number?(phone) + def self.valid_phone_number?(phone) /\A\+?[0-9]{9,15}\z/.match?(phone) end - # self - def valid_telegram?(telegram) + def self.valid_telegram?(telegram) /\A@[A-Za-z0-9_]{5,32}\z/.match?(telegram) end - def valid_email?(email) + def self.valid_email?(email) /\A[^@\s]+@[^@\s]+\.[^@\s]+\z/.match?(email) end - public - def self.new_from_info(info_string) info_string = info_string.sub(/^Contact: /, '').strip