feat: add validation setters in Contact class and refine Person and StudentShort classes

lab2
Artem-Darius Weber 1 week ago
parent 1f750e1334
commit 7e7110f01e

@ -1,4 +1,5 @@
class Contact
# add setters with validation
attr_reader :phone, :telegram, :email
def initialize(args = {})
@ -20,6 +21,7 @@ class Contact
@phone || @telegram || @email
end
# getSingleContact
def info
return "Phone: #{@phone}" if @phone
return "Telegram: #{@telegram}" if @telegram
@ -34,6 +36,7 @@ class Contact
/\A\+?[0-9]{9,15}\z/.match?(phone)
end
# self
def valid_telegram?(telegram)
/\A@[A-Za-z0-9_]{5,32}\z/.match?(telegram)
end

@ -1,6 +1,7 @@
require_relative 'contact'
class Person
# contact только в этом классе, убрать из наследуемых переопределение
attr_reader :id, :git, :contact
def initialize(id:, git:, contact: Contact.new)

@ -1,7 +1,7 @@
require_relative 'person'
class StudentShort < Person
attr_reader :surname_initials, :contact
attr_reader :surname_initials
def initialize(id:, git:, surname_initials:, contact:)
super(id: id, git: git, contact: contact)
@ -38,4 +38,4 @@ class StudentShort < Person
def to_s
"#{@surname_initials}, Git: #{@git}, Contact: #{@contact}"
end
end
end
Loading…
Cancel
Save