Class: StudentBase

Inherits:
Object
  • Object
show all
Defined in:
lib/models/student_base.rb

Direct Known Subclasses

Student, StudentShort

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, phone: nil, telegram: nil, email: nil, git: nil) ⇒ StudentBase

Стандартный конструктор



36
37
38
39
40
41
42
# File 'lib/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

#gitObject

Returns the value of attribute git.



33
34
35
# File 'lib/models/student_base.rb', line 33

def git
  @git
end

#idObject

Returns the value of attribute id.



33
34
35
# File 'lib/models/student_base.rb', line 33

def id
  @id
end

Class Method Details

.valid_email?(email) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/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

Валидаторы для полей

Returns:

  • (Boolean)


8
9
10
# File 'lib/models/student_base.rb', line 8

def self.valid_name?(name)
  name.match(/(^[А-Я][а-я]+$)|(^[A-Z][a-z]+$)/)
end

.valid_phone?(phone) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/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

Returns:

  • (Boolean)


16
17
18
# File 'lib/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

Валидаторы объекта

Returns:

  • (Boolean)


89
90
91
# File 'lib/models/student_base.rb', line 89

def has_contacts?
  !phone.nil? || !telegram.nil? || !email.nil?
end

#has_git?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/models/student_base.rb', line 93

def has_git?
  !git.nil?
end

#short_contactObject

Краткая информация о первом доступном контакте пользователя



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/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

Returns:

  • (Boolean)


97
98
99
# File 'lib/models/student_base.rb', line 97

def valid?
  has_contacts? && has_git?
end