refactor: streamline initialization and validation in Person class

lab2
Artem-Darius Weber 1 month ago
parent dc752cdf43
commit e79d92eed3

@ -4,7 +4,9 @@ class Person
def initialize(args = {})
@id = args[:id] || nil
@git = args[:git]
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 set_contacts(phone: nil, telegram: nil, email: nil)
@ -46,11 +48,6 @@ class Person
!(@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 contact_info
return "Phone: #{@phone}" if @phone
return "Telegram: #{@telegram}" if @telegram

Loading…
Cancel
Save