Class: StudentBase
- Inherits:
-
Object
- Object
- StudentBase
- Defined in:
- lib/source/models/student_base.rb
Overview
Абстрактный класс с базовым описанием студента
Direct Known Subclasses
Instance Attribute Summary collapse
-
#git ⇒ Object
readonly
Returns the value of attribute git.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
-
.valid_email?(email) ⇒ Boolean
Валидация email.
-
.valid_name?(name) ⇒ Boolean
Валидация имени (также применимо к фамилии и отчеству).
-
.valid_phone?(phone) ⇒ Boolean
Валидация номера телефона.
-
.valid_profile_name?(profile_name) ⇒ Boolean
Валидация имени профиля пользователя.
Instance Method Summary collapse
-
#has_contacts? ⇒ Boolean
Возвращает true, если у студента есть хотя бы один из контактов.
-
#has_git? ⇒ Boolean
Возвращает true, если у студента есть гит.
-
#initialize(id: nil, phone: nil, telegram: nil, email: nil, git: nil) ⇒ StudentBase
constructor
Стандартный конструктор.
-
#short_contact ⇒ Object
Возвращает первый доступный контакт пользователя в виде хеша.
-
#valid? ⇒ Boolean
Возвращает true, если у студента есть хотя бы один из контактов и гит.
Constructor Details
#initialize(id: nil, phone: nil, telegram: nil, email: nil, git: nil) ⇒ StudentBase
Стандартный конструктор. Принимает именованные параметры: id - Id студента phone - Телефон telegram - Ник в телеграме email - Электронная почта git - Ник на гите
54 55 56 57 58 59 60 |
# File 'lib/source/models/student_base.rb', line 54 def initialize(id: nil, phone: nil, telegram: nil, email: nil, git: nil) self.id = id self.phone = phone self.telegram = telegram self.email = email self.git = git end |
Instance Attribute Details
#git ⇒ Object
Returns the value of attribute git.
44 45 46 |
# File 'lib/source/models/student_base.rb', line 44 def git @git end |
#id ⇒ Object
Returns the value of attribute id.
44 45 46 |
# File 'lib/source/models/student_base.rb', line 44 def id @id end |
Class Method Details
.valid_email?(email) ⇒ Boolean
Валидация email
33 34 35 |
# File 'lib/source/models/student_base.rb', line 33 def self.valid_email?(email) email.match(/^(?:[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/) end |
.valid_name?(name) ⇒ Boolean
Валидация имени (также применимо к фамилии и отчеству)
12 13 14 |
# File 'lib/source/models/student_base.rb', line 12 def self.valid_name?(name) name.match(/(^[А-Я][а-я]+$)|(^[A-Z][a-z]+$)/) end |
.valid_phone?(phone) ⇒ Boolean
Валидация номера телефона
19 20 21 |
# File 'lib/source/models/student_base.rb', line 19 def self.valid_phone?(phone) phone.match(/^\+?[78] ?[(-]?\d{3} ?[)-]?[ -]?\d{3}[ -]?\d{2}[ -]?\d{2}$/) end |
.valid_profile_name?(profile_name) ⇒ Boolean
Валидация имени профиля пользователя
26 27 28 |
# File 'lib/source/models/student_base.rb', line 26 def self.valid_profile_name?(profile_name) profile_name.match(/^[a-zA-Z0-9_.]+$/) end |
Instance Method Details
#has_contacts? ⇒ Boolean
Возвращает true, если у студента есть хотя бы один из контактов
111 112 113 |
# File 'lib/source/models/student_base.rb', line 111 def has_contacts? !phone.nil? || !telegram.nil? || !email.nil? end |
#has_git? ⇒ Boolean
Возвращает true, если у студента есть гит
118 119 120 |
# File 'lib/source/models/student_base.rb', line 118 def has_git? !git.nil? end |
#short_contact ⇒ Object
Возвращает первый доступный контакт пользователя в виде хеша. Пример: :telegram, value: ‘xoxolovelylove’
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/source/models/student_base.rb', line 66 def short_contact contact = {} %i[telegram email phone].each do |attr| attr_val = send(attr) next if attr_val.nil? contact[:type] = attr contact[:value] = attr_val return contact end nil end |
#valid? ⇒ Boolean
Возвращает true, если у студента есть хотя бы один из контактов и гит
125 126 127 |
# File 'lib/source/models/student_base.rb', line 125 def valid? has_contacts? && has_git? end |