You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
844 B
43 lines
844 B
require_relative 'contact'
|
|
|
|
class Person
|
|
attr_accessor :id, :git
|
|
attr_reader :contact
|
|
|
|
def initialize(id:, git:, contact: Contact.new)
|
|
@id = id
|
|
@git = git
|
|
@contact = contact
|
|
|
|
validate_person
|
|
end
|
|
|
|
def git_present?
|
|
!@git.nil? && !@git.empty?
|
|
end
|
|
|
|
def contact_present?
|
|
@contact.present?
|
|
end
|
|
|
|
def contact_info
|
|
@contact.info
|
|
end
|
|
|
|
def self.valid_git?(git)
|
|
/\Ahttps:\/\/github\.com\/[A-Za-z0-9_\-]+\z/.match?(git)
|
|
end
|
|
|
|
def self.valid_id?(id)
|
|
id.is_a?(String) && !id.strip.empty?
|
|
end
|
|
|
|
private
|
|
|
|
def validate_person
|
|
raise ArgumentError, 'ID is required and must be a non-empty string' unless self.class.valid_id?(@id)
|
|
raise ArgumentError, 'Git link is required' unless git_present?
|
|
raise ArgumentError, 'Invalid Git link format' unless self.class.valid_git?(@git)
|
|
end
|
|
end
|