diff --git a/lab2/README.md b/lab2/README.md index 28468bf..9d7c6cc 100644 --- a/lab2/README.md +++ b/lab2/README.md @@ -25,12 +25,14 @@ classDiagram - telegram : String? - email : String? + Contact(phone : String?, telegram : String?, email : String?) - + valid_phone_number() : Boolean - + valid_telegram() : Boolean - + valid_email() : Boolean + present() : Boolean - + info() : String - - validate_contacts() + + get_single_contact() : String + + phone=(String) : Boolean + + telegram=(String) : Boolean + + email=(String) : Boolean + + self.valid_phone_number() : Boolean + + self.valid_telegram() : Boolean + + self.valid_email() : Boolean + new_from_info(info_string : String) : Contact } @@ -42,9 +44,12 @@ classDiagram + git_present() : Boolean + contact_present() : Boolean + contact_info() : String - + valid_git(git : String) : Boolean - + valid_id(id : String) : Boolean - - validate_person() + + git=(String) : Boolean + - validate_id(id: String) : Boolean + - validate_git(id: String) : Boolean + + - valid_git(git : String) : Boolean + - valid_id(id : String) : Boolean } class StudentRepository { diff --git a/lab2/person.rb b/lab2/person.rb index 09ad955..ae90c5a 100644 --- a/lab2/person.rb +++ b/lab2/person.rb @@ -1,12 +1,10 @@ -require_relative 'contact' - class Person attr_reader :id, :git, :contact def initialize(id:, git:, contact: Contact.new) - validate_id(id) - validate_contact(contact) - + self.class.validate_id(id) + self.class.validate_contact(contact) + @id = id @git = git @contact = contact @@ -24,32 +22,31 @@ class Person @contact.get_single_contact 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 - def git=(git) - validate_git(git) + self.class.validate_git(git) @git = git end - private - - def validate_id(id) - raise ArgumentError, 'ID is required and must be a non-empty string' unless self.class.valid_id?(id) + # Методы класса + def self.validate_id(id) + raise ArgumentError, 'ID is required and must be a non-empty string' unless valid_id?(id) end - def validate_git(git) + def self.validate_git(git) raise ArgumentError, 'Git link is required' if git.nil? || git.strip.empty? - raise ArgumentError, 'Invalid Git link format' unless self.class.valid_git?(git) + raise ArgumentError, 'Invalid Git link format' unless valid_git?(git) end - def validate_contact(contact) + def self.validate_contact(contact) raise ArgumentError, 'Contact must be a valid Contact object' unless contact.is_a?(Contact) raise ArgumentError, 'Contact must have at least one valid field' unless contact.present? end -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 +end \ No newline at end of file