refactor: convert instance validation methods to class methods in Contact class

lab2
Artem-Darius Weber 1 week ago
parent 0b3d315370
commit d5f67c2de0

@ -29,23 +29,18 @@ class Contact
'No contact available' 'No contact available'
end end
private def self.valid_phone_number?(phone)
def valid_phone_number?(phone)
/\A\+?[0-9]{9,15}\z/.match?(phone) /\A\+?[0-9]{9,15}\z/.match?(phone)
end end
# self def self.valid_telegram?(telegram)
def valid_telegram?(telegram)
/\A@[A-Za-z0-9_]{5,32}\z/.match?(telegram) /\A@[A-Za-z0-9_]{5,32}\z/.match?(telegram)
end end
def valid_email?(email) def self.valid_email?(email)
/\A[^@\s]+@[^@\s]+\.[^@\s]+\z/.match?(email) /\A[^@\s]+@[^@\s]+\.[^@\s]+\z/.match?(email)
end end
public
def self.new_from_info(info_string) def self.new_from_info(info_string)
info_string = info_string.sub(/^Contact: /, '').strip info_string = info_string.sub(/^Contact: /, '').strip

Loading…
Cancel
Save