Class: StudentBase
- Inherits:
-
Object
- Object
- StudentBase
- Defined in:
- lib/source/models/student_base.rb
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
-
.valid_name?(name) ⇒ Boolean
Валидаторы для полей.
- .valid_phone?(phone) ⇒ Boolean
- .valid_profile_name?(profile_name) ⇒ Boolean
Instance Method Summary collapse
-
#has_contacts? ⇒ Boolean
Валидаторы объекта.
- #has_git? ⇒ Boolean
-
#initialize(id: nil, phone: nil, telegram: nil, email: nil, git: nil) ⇒ StudentBase
constructor
Стандартный конструктор.
-
#short_contact ⇒ Object
Краткая информация о первом доступном контакте пользователя.
- #valid? ⇒ Boolean
Constructor Details
#initialize(id: nil, phone: nil, telegram: nil, email: nil, git: nil) ⇒ StudentBase
Стандартный конструктор
36 37 38 39 40 41 42 |
# File 'lib/source/models/student_base.rb', line 36 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.
33 34 35 |
# File 'lib/source/models/student_base.rb', line 33 def git @git end |
#id ⇒ Object
Returns the value of attribute id.
33 34 35 |
# File 'lib/source/models/student_base.rb', line 33 def id @id end |
Class Method Details
.valid_email?(email) ⇒ Boolean
20 21 22 |
# File 'lib/source/models/student_base.rb', line 20 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
Валидаторы для полей
8 9 10 |
# File 'lib/source/models/student_base.rb', line 8 def self.valid_name?(name) name.match(/(^[А-Я][а-я]+$)|(^[A-Z][a-z]+$)/) end |
.valid_phone?(phone) ⇒ Boolean
12 13 14 |
# File 'lib/source/models/student_base.rb', line 12 def self.valid_phone?(phone) phone.match(/^\+?[78] ?[(-]?\d{3} ?[)-]?[ -]?\d{3}[ -]?\d{2}[ -]?\d{2}$/) end |
.valid_profile_name?(profile_name) ⇒ Boolean
16 17 18 |
# File 'lib/source/models/student_base.rb', line 16 def self.valid_profile_name?(profile_name) profile_name.match(/^[a-zA-Z0-9_.]+$/) end |
Instance Method Details
#has_contacts? ⇒ Boolean
Валидаторы объекта
89 90 91 |
# File 'lib/source/models/student_base.rb', line 89 def has_contacts? !phone.nil? || !telegram.nil? || !email.nil? end |
#has_git? ⇒ Boolean
93 94 95 |
# File 'lib/source/models/student_base.rb', line 93 def has_git? !git.nil? end |
#short_contact ⇒ Object
Краткая информация о первом доступном контакте пользователя
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/source/models/student_base.rb', line 45 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
97 98 99 |
# File 'lib/source/models/student_base.rb', line 97 def valid? has_contacts? && has_git? end |