- Added class methods to validate the format of strings for each field:
- `valid_name?` for surname, name, and patronymic (only letters allowed).
- `valid_phone_number?` for phone number (validates 10-15 digits, optional '+' sign).
- `valid_telegram?` for telegram handle (starts with '@' and allows letters, digits, and underscores).
- `valid_email?` for email (standard email format validation).
- `valid_git?` for Git link (validates GitHub URL format).
- Modified the `initialize` constructor:
- Integrated validations for all fields with descriptive error messages.
- Ensured objects cannot be created with invalid data formats.
- Added `validate` method to ensure each Student object has a Git link and at least one contact method (phone, telegram, or email).
- Implemented `git_present?` method to check the presence of a Git link.
- Implemented `contact_present?` method to check the presence of at least one contact method.
- Modified the constructor to call `validate` during object initialization.
- Implemented `set_contacts` method to safely set phone, telegram, and email fields.
- Made contact fields (`phone`, `telegram`, `email`) private and accessible only through `set_contacts`.
- Added validation within `set_contacts` to ensure contact fields are correctly formatted.
- Modified the `initialize` method to utilize `set_contacts` for setting contact values during object creation.
- Added checks in the `validate` method to ensure Git presence and at least one contact method.
- Updated test cases in `main.rb` to demonstrate correct and incorrect uses of contact modifications.
- Ensured that contact fields cannot be modified directly, maintaining data integrity.
- Updated `to_s` method to standardize string representation of Student object.
- Added `from_string` constructor that parses a formatted string and initializes the object with parsed data.
- Modified `set_contacts` to ensure contacts are only set via the defined method.
- Added validation for Git presence and contact details presence, ensuring data integrity.
- Updated tests in main.rb to validate the new constructor and string parsing logic.
- Added `get_info` method to return a concise summary of the student, including surname with initials, Git link, and primary contact method.
- Implemented individual methods for retrieving surname with initials, Git link, and contact information separately.
- Protected contact fields from direct modification; fields can now only be updated via `set_contacts`.
- Enhanced string parsing with `from_string` constructor to initialize objects directly from formatted strings.
- Updated main file to test new methods and constructor functionality.
- Created StudentShort class with fields: ID, surname initials, git, and contact, which cannot be modified directly.
- Implemented two constructors:
1. One that accepts a Student object to initialize fields.
2. Another that accepts ID and a string containing surname initials, git, and contact information.
- Updated main.rb to test both constructors of StudentShort, ensuring proper field initialization and immutability.
- Created a new superclass `Person` to encapsulate common attributes and methods for `Student` and `StudentShort`.
- Moved validation methods, contact handling, and common logic from `Student` and `StudentShort` into `Person`.
- Updated `Student` to inherit from `Person`, simplifying initialization and validation.
- Updated `StudentShort` to inherit from `Person`, reducing redundancy and aligning with the new superclass structure.
- Improved code maintainability by eliminating duplicated code and clarifying class responsibilities.
избавиться от метода validate поскольку он возвращает bool
- [x] Написать диаграмму классов
- [x] Реализовать в куске кода
```
def initialize(args = {})
@id = args[:id] || nil
@git = args[:git]
validate
end
```
аргументы в {}
- [x] избавиться от метода validate поскольку он возвращает bool
по диаграмме не видно где метод класса а где метод объекта.
contact_info() дублирует getter contact из short students
getters and setters не включены в диаграмму
- [ ] переопределение getter & setter
```
attr_accessor :id, :git:
```
- [ ] по диаграмме не видно где метод класса а где метод объекта.
- [ ] contact_info() дублирует getter contact из short students
- [ ] getters and setters не включены в диаграмму
dev logs: #2
bd196668af
into main 4 months agoНаписать диаграмму классов
Реализовать в куске кода
аргументы в {}
https://medium.com/@rossabaker/what-is-the-purpose-of-attr-accessor-in-ruby-3bf3f423f573
https://www.rubyguides.com/2018/11/attr_accessor/
в StudentShort можно использовать конструктор из Student
bd196668af
.