shanti555890 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/shanti555890/version.rb +5 -0
- data/lib/shanti555890.rb +10 -0
- data/lib/source/add_controller.rb +53 -0
- data/lib/source/all_data/data_list.rb +76 -0
- data/lib/source/all_data/data_list_student_short.rb +16 -0
- data/lib/source/all_data/data_table.rb +38 -0
- data/lib/source/controller.rb +103 -0
- data/lib/source/database/add_controller.rb +53 -0
- data/lib/source/database/controller.rb +103 -0
- data/lib/source/database/create.sql +10 -0
- data/lib/source/database/db_university.rb +31 -0
- data/lib/source/database/dialog_create_student.rb +97 -0
- data/lib/source/database/insert.sql +3 -0
- data/lib/source/database/observer.rb +53 -0
- data/lib/source/database/student_file_adapter.rb +37 -0
- data/lib/source/database/student_list.rb +34 -0
- data/lib/source/database/student_list_db.rb +77 -0
- data/lib/source/database/update_contact_controller.rb +9 -0
- data/lib/source/database/update_controller.rb +29 -0
- data/lib/source/database/update_git_controller.rb +9 -0
- data/lib/source/database/update_name_controller.rb +9 -0
- data/lib/source/database/window.rb +59 -0
- data/lib/source/strategy/student_list_base.rb +80 -0
- data/lib/source/strategy/student_list_json.rb +16 -0
- data/lib/source/strategy/student_list_strat.rb +12 -0
- data/lib/source/strategy/student_list_txt.rb +42 -0
- data/lib/source/strategy/student_list_yaml.rb +18 -0
- data/lib/source/student/student.rb +156 -0
- data/lib/source/student/student_short.rb +50 -0
- data/lib/source/student/student_test.rb +86 -0
- data/lib/source/update_contact_controller.rb +9 -0
- data/lib/source/update_controller.rb +29 -0
- data/lib/source/update_git_controller.rb +9 -0
- data/lib/source/update_name_controller.rb +9 -0
- data/shanti555890.gemspec +17 -0
- data/sig/shanti555890.rbs +4 -0
- metadata +93 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require_relative '../strategy/student_list_base'
|
|
3
|
+
class StudentFileAdapter
|
|
4
|
+
def initialize(type_file,file_address)
|
|
5
|
+
@file = StudentListBase.new(type_file)
|
|
6
|
+
@file.load_from_file(file_address)
|
|
7
|
+
@file_address = file_address
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def student_by_id(id_student)
|
|
11
|
+
@file.student_by_id(id_student)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def add_student(student)
|
|
15
|
+
@file.add_student(student)
|
|
16
|
+
@file.save_to_file(@file_address)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def delete_student(id_student)
|
|
20
|
+
@file.delete_student(id_student)
|
|
21
|
+
@file.save_to_file(@file_address)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def replace_student(id_student, student)
|
|
25
|
+
@file.replace_student(id_student, student)
|
|
26
|
+
|
|
27
|
+
@file.save_to_file(@file_address)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def count_student
|
|
31
|
+
@file.count_student
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def get_k_n_student_short_list(page,n, data_list)
|
|
35
|
+
@file.get_k_n_student_short_list(page, n, data_list)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class StudentList
|
|
4
|
+
|
|
5
|
+
def initialize(adapter)
|
|
6
|
+
@adapter = adapter
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def student_by_id(id_student)
|
|
10
|
+
@adapter.student_by_id(id_student)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def add_student(student)
|
|
14
|
+
@adapter.add_student(student)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def delete_student(id_student)
|
|
18
|
+
@adapter.delete_student(id_student)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def replace_student(id_student, student)
|
|
22
|
+
@adapter.replace_student(id_student, student)
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def count_student
|
|
27
|
+
@adapter.count_student
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def get_k_n_student_short_list(k,n,data_list)
|
|
31
|
+
@adapter.get_k_n_student_short_list(k,n,data_list)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require_relative 'db_university'
|
|
3
|
+
require 'json'
|
|
4
|
+
class StudentListDBAdapter
|
|
5
|
+
|
|
6
|
+
def initialize
|
|
7
|
+
self.client = DBUniversity.instance
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def into_hash(arr)
|
|
11
|
+
attrs = {}
|
|
12
|
+
i=0
|
|
13
|
+
%i[id first_name middle_name surname phone_number telegram mail git].each do |attr|
|
|
14
|
+
attrs[attr] = arr[i] unless arr[i].nil?
|
|
15
|
+
i=i+1
|
|
16
|
+
end
|
|
17
|
+
attrs
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def student_by_id(id_student)
|
|
21
|
+
id_student=id_student.first.to_i
|
|
22
|
+
hash = client.prepare_exec('SELECT * FROM students WHERE id = ?',id_student).first
|
|
23
|
+
|
|
24
|
+
hash = into_hash(hash)
|
|
25
|
+
return nil if hash.nil?
|
|
26
|
+
|
|
27
|
+
Student.new(**hash)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# def add_student(student)
|
|
31
|
+
# st = client.prepare_exec('insert into students (first_name, middle_name, surname, phone_number,
|
|
32
|
+
# telegram, mail, git) VALUES (?, ?, ?, ?, ?, ?, ?)')
|
|
33
|
+
# st.execute(*student_attr(student))
|
|
34
|
+
# self.client.query('SELECT seq from sqlite_sequence where name = "students"').first.first[1]
|
|
35
|
+
# end
|
|
36
|
+
def add_student(student)
|
|
37
|
+
client.prepare_exec('insert into students (first_name, middle_name, surname, phone_number, telegram, mail, git) VALUES (?, ?, ?, ?, ?, ?, ?)', *student_attr(student)).first
|
|
38
|
+
end
|
|
39
|
+
def delete_student(id_student)
|
|
40
|
+
client.prepare_exec('DELETE FROM students WHERE id = ?', id_student)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def replace_student(id_student, student)
|
|
44
|
+
st ='UPDATE students SET first_name=?, middle_name=?, surname=?, phone_number=?, telegram=?, mail=?, git=? WHERE id=?'
|
|
45
|
+
client.prepare_exec(st,*student_attr(student), id_student)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def count_student
|
|
49
|
+
client.query('SELECT COUNT(id) FROM students').next[0]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def get_k_n_student_short_list(k,n,data_list)
|
|
53
|
+
offset = (k - 1) * n
|
|
54
|
+
students = client.prepare_exec('SELECT * FROM students LIMIT ?, ?', offset, n)
|
|
55
|
+
puts students.to_s
|
|
56
|
+
slice = students.map { |h|
|
|
57
|
+
h = h.transform_keys(&:to_sym)
|
|
58
|
+
StudentShort.new(Student.new(**h)) }
|
|
59
|
+
|
|
60
|
+
puts slice
|
|
61
|
+
DataListStudentShort.new(slice)
|
|
62
|
+
data_list.replace_objects(slice)
|
|
63
|
+
data_list
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
private
|
|
69
|
+
|
|
70
|
+
attr_accessor :client
|
|
71
|
+
def student_attr(student)
|
|
72
|
+
[student.first_name, student.middle_name, student.surname,
|
|
73
|
+
student.phone_number, student.telegram,
|
|
74
|
+
student.mail, student.git]
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'controller'
|
|
4
|
+
require_relative 'add_controller'
|
|
5
|
+
require 'logger'
|
|
6
|
+
class UpdateStudentController<AddStudentController
|
|
7
|
+
private_class_method :new
|
|
8
|
+
def initialize(student_list, student_id)
|
|
9
|
+
super(student_list)
|
|
10
|
+
@student_id = student_id
|
|
11
|
+
@logger = Logger.new('controller_update.log') # Указывает путь и имя файла для логов
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def add_view(view)
|
|
15
|
+
@logger.info('Adding view to update student controller')
|
|
16
|
+
super(view)
|
|
17
|
+
student = @student_list.student_by_id(@student_id)
|
|
18
|
+
puts student.class
|
|
19
|
+
@view.set_student(student, get_editable_fields)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def save_student(student)
|
|
23
|
+
@logger.info('Saving updated student')
|
|
24
|
+
puts student.to_hash
|
|
25
|
+
@student_list.replace_student(@student_id, student)
|
|
26
|
+
end
|
|
27
|
+
private
|
|
28
|
+
def get_editable_fields; end
|
|
29
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require 'fox16'
|
|
2
|
+
include Fox
|
|
3
|
+
require_relative 'controller'
|
|
4
|
+
require_relative 'dialog_create_student'
|
|
5
|
+
require_relative '../database_labs/tab_lab'
|
|
6
|
+
require_relative '../database_labs/tab_student'
|
|
7
|
+
class Window < FXMainWindow
|
|
8
|
+
def initialize(app)
|
|
9
|
+
super(app, "Students", width: 1100, height: 800) # увеличиваем размер главного окна
|
|
10
|
+
create_tabs
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def create
|
|
14
|
+
super
|
|
15
|
+
#@controller.refresh_data(@current_page, @students_on_page)
|
|
16
|
+
@first_tab.refresh
|
|
17
|
+
show
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def create_tabs
|
|
21
|
+
tab_book = FXTabBook.new(self, :opts=>LAYOUT_FILL_X|LAYOUT_FILL_Y)
|
|
22
|
+
# Создаем первую вкладку
|
|
23
|
+
tab1 = FXTabItem.new(tab_book, "Вкладка 1", nil)
|
|
24
|
+
composite1 = FXComposite.new(tab_book, LAYOUT_FILL_X|LAYOUT_FILL_Y)
|
|
25
|
+
@first_tab = TabStudent.new(composite1)
|
|
26
|
+
@first_tab.resize(1000,1000)
|
|
27
|
+
|
|
28
|
+
# Создаем вторую вкладку
|
|
29
|
+
tab2 = FXTabItem.new(tab_book, "Вкладка 2", nil)
|
|
30
|
+
composite2 = FXComposite.new(tab_book, LAYOUT_FILL_X|LAYOUT_FILL_Y)
|
|
31
|
+
@second_tab = TabLab.new(composite2)
|
|
32
|
+
@second_tab.resize(1000,1000)
|
|
33
|
+
|
|
34
|
+
tab3 = FXTabItem.new(tab_book, "Вкладка 3", nil)
|
|
35
|
+
composite3 = FXComposite.new(tab_book, LAYOUT_FILL_X|LAYOUT_FILL_Y)
|
|
36
|
+
|
|
37
|
+
tab_book.connect(SEL_COMMAND) do |sender, selector, data|
|
|
38
|
+
# Получаем индекс текущей вкладки
|
|
39
|
+
current_tab_index = sender.current
|
|
40
|
+
# Обновляем данные в соответствии с текущей вкладкой
|
|
41
|
+
case current_tab_index
|
|
42
|
+
when 0
|
|
43
|
+
# для первой вкладки
|
|
44
|
+
@first_tab.refresh
|
|
45
|
+
when 1
|
|
46
|
+
# для второй вкладки
|
|
47
|
+
@second_tab.refresh
|
|
48
|
+
# when 2
|
|
49
|
+
# # для третьей вкладки
|
|
50
|
+
# @controller.refresh_data_for_tab3
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
private
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class StudentListBase
|
|
4
|
+
|
|
5
|
+
attr_writer :data_type
|
|
6
|
+
|
|
7
|
+
# конструктор
|
|
8
|
+
def initialize(data_type)
|
|
9
|
+
self.students = []
|
|
10
|
+
self.this_id = 1
|
|
11
|
+
self.data_type = data_type
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def load_from_file(file_address)
|
|
15
|
+
list = data_type.string_to_list(File.read(file_address))
|
|
16
|
+
self.students = list.map{ |i|
|
|
17
|
+
Student.new(**i)
|
|
18
|
+
}
|
|
19
|
+
new_this_id
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def save_to_file(file_address)
|
|
23
|
+
list = students.map(&:to_hash)
|
|
24
|
+
File.write(file_address, data_type.list_to_string(list))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def student_by_id(student_id)
|
|
28
|
+
r = students.detect { |student_i| student_i.id == student_id}
|
|
29
|
+
puts r.class
|
|
30
|
+
puts 888888
|
|
31
|
+
r
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def sort_students
|
|
35
|
+
students.sort_by(&:short_name)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def add_student(student)
|
|
39
|
+
student.id = this_id
|
|
40
|
+
students << student
|
|
41
|
+
self.this_id += 1
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def replace_student(id, student)
|
|
45
|
+
this_student = students.find_index {
|
|
46
|
+
|stud|
|
|
47
|
+
stud.id == id
|
|
48
|
+
}
|
|
49
|
+
students[this_student] = student
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def delete_student(id)
|
|
53
|
+
students.reject!{|stud| stud.id == id}
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def get_student_short_count
|
|
57
|
+
students.size
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def k_n_student_short_list(k, n, data_list)
|
|
61
|
+
move = (k - 1) * n
|
|
62
|
+
piece = students[move, n].map {|stud| StudentShort.new(stud) }
|
|
63
|
+
return DataListStudentShort.new(piece) if data_list.nil?
|
|
64
|
+
|
|
65
|
+
#data_list.append(slice)
|
|
66
|
+
data_list.replace_objects(slice)
|
|
67
|
+
data_list
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
protected
|
|
71
|
+
|
|
72
|
+
attr_accessor :students, :this_id
|
|
73
|
+
|
|
74
|
+
private
|
|
75
|
+
|
|
76
|
+
def new_this_id
|
|
77
|
+
self.this_id = students.max_by(&:id).id.to_i + 1
|
|
78
|
+
end
|
|
79
|
+
attr_reader :data_type
|
|
80
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require_relative 'student_list_strat'
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
class StudentListJson < StudentListStrategy
|
|
6
|
+
|
|
7
|
+
public_class_method :new
|
|
8
|
+
|
|
9
|
+
def string_to_list(str)
|
|
10
|
+
JSON.parse(str, {symbolize_names: true})
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def list_to_string(list)
|
|
14
|
+
JSON.generate(list)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require_relative 'student_list_strat'
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
class StudentListTxt < StudentListStrategy
|
|
6
|
+
public_class_method :new
|
|
7
|
+
|
|
8
|
+
def string_to_list(str)
|
|
9
|
+
to_hash(str.split("\n").map(&:chomp))
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def list_to_string(list)
|
|
13
|
+
to_string(list)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
def to_hash( list_strings)
|
|
18
|
+
list_hashes = []
|
|
19
|
+
list_strings.each do
|
|
20
|
+
|str|
|
|
21
|
+
str = str.gsub('"', "")
|
|
22
|
+
h = {}
|
|
23
|
+
str.split(',').each do |atr|
|
|
24
|
+
key, value = atr.split(':').map(&:strip)
|
|
25
|
+
h[key.to_sym] = value
|
|
26
|
+
end
|
|
27
|
+
list_hashes << h
|
|
28
|
+
end
|
|
29
|
+
list_hashes
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def to_string (hashes)
|
|
33
|
+
str = hashes.map do
|
|
34
|
+
|h|
|
|
35
|
+
h.map{
|
|
36
|
+
|key, value|
|
|
37
|
+
"#{key}: #{value.inspect}"
|
|
38
|
+
}.join(",")
|
|
39
|
+
end
|
|
40
|
+
str.join("\n")
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require_relative 'student_list_strat'
|
|
3
|
+
require 'yaml'
|
|
4
|
+
|
|
5
|
+
class StudentListYaml<StudentListStrategy
|
|
6
|
+
public_class_method :new
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def string_to_list(str)
|
|
10
|
+
YAML.safe_load(str).map {|h| h.transform_keys(&:to_sym)}
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def list_to_string(list)
|
|
14
|
+
list.map {
|
|
15
|
+
|h|
|
|
16
|
+
h.transform_keys(&:to_s)}.to_yaml
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
|
|
2
|
+
require 'json'
|
|
3
|
+
require_relative 'student_short'
|
|
4
|
+
class Student < StudentShort
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
attr_reader :first_name, :middle_name, :phone_number, :mail , :telegram
|
|
8
|
+
def self.is_phone?(phone_number)
|
|
9
|
+
raise ArgumentError, "arg '#{phone_number}' is not string" unless phone_number.class == String or phone_number.nil?
|
|
10
|
+
return true if phone_number=~/^(\+7|8)\s?(\(\d{3}\)|\d{3})[\s\-]?\d{3}[\s\-]?\d{2}[\s\-]?\d{2}/ or phone_number.nil?
|
|
11
|
+
|
|
12
|
+
false
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.is_name?(name)
|
|
16
|
+
raise ArgumentError, "arg '#{name}' is not string" unless name.class == String
|
|
17
|
+
return true if name=~/^[А-Яа-я]+$/
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.is_mail?(mail)
|
|
21
|
+
raise ArgumentError, "arg '#{mail}' is not string" unless mail.class == String or mail.nil?
|
|
22
|
+
return true if mail=~/^[^@\s]+@[^@\s]+\.\w+$/ or mail.nil?
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.is_git?(git)
|
|
26
|
+
raise ArgumentError, "arg '#{git}' is not string" unless git.class == String or git.nil?
|
|
27
|
+
return true if git=~/^github\.com\/[a-zA-Z0-9\-_]+$/ or git.nil?
|
|
28
|
+
|
|
29
|
+
false
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.is_telegram?(telegram)
|
|
33
|
+
raise ArgumentError, "arg '#{telegram}' is not string" unless telegram.class == String or telegram.nil?
|
|
34
|
+
return true if telegram=~/^@[^@]+$/ or telegram.nil?
|
|
35
|
+
|
|
36
|
+
false
|
|
37
|
+
end
|
|
38
|
+
def self.from_hash(hash)
|
|
39
|
+
hash=hash.dup
|
|
40
|
+
Student.new(**hash)
|
|
41
|
+
end
|
|
42
|
+
#конструктор
|
|
43
|
+
def initialize(first_name: nil, middle_name:nil, surname:nil, id:nil,phone_number:nil, git:nil,telegram:nil, mail:nil)
|
|
44
|
+
self.first_name = first_name
|
|
45
|
+
self.middle_name = middle_name
|
|
46
|
+
self.surname = surname
|
|
47
|
+
self.id = id
|
|
48
|
+
self.git = git
|
|
49
|
+
set_contacts(phone_number: phone_number,mail: mail, telegram:telegram)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def short_name
|
|
53
|
+
"#{surname} #{first_name[0]}. #{middle_name[0]}."
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def get_info
|
|
57
|
+
info = {}
|
|
58
|
+
info[:short_name] = short_name
|
|
59
|
+
info[:contact] = contact
|
|
60
|
+
info[:git] = git
|
|
61
|
+
JSON.generate(info)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def self.pars_str(str)
|
|
65
|
+
args = JSON.parse(str)
|
|
66
|
+
raise ArgumentError,"The argument must have first_name, middle_name and surname" unless
|
|
67
|
+
(args.has_key?('first_name') and args.has_key?('middle_name') and args.has_key?('surname'))
|
|
68
|
+
|
|
69
|
+
new(first_name: args['first_name'], middle_name: args['middle_name'],
|
|
70
|
+
surname: args['surname'], id: args['id'],
|
|
71
|
+
git: args['git'],
|
|
72
|
+
phone_number: args['phone_number'], telegram: args['telegram'],
|
|
73
|
+
mail: args['mail'])
|
|
74
|
+
end
|
|
75
|
+
def to_hash
|
|
76
|
+
info_hash = {}
|
|
77
|
+
%i[first_name middle_name surname id phone_number telegram mail git].each do |field|
|
|
78
|
+
info_hash[field] = send(field) unless send(field).nil?
|
|
79
|
+
end
|
|
80
|
+
info_hash
|
|
81
|
+
end
|
|
82
|
+
def set_contacts(phone_number:nil, mail:nil, telegram:nil)
|
|
83
|
+
self.phone_number = phone_number unless phone_number.nil?
|
|
84
|
+
self.mail = mail unless mail.nil?
|
|
85
|
+
self.telegram = telegram unless telegram.nil?
|
|
86
|
+
@contact = contact
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
#сеттеры
|
|
90
|
+
def id=(id_value)
|
|
91
|
+
@id=id_value
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def first_name=(first_name_value)
|
|
95
|
+
raise ArgumentError, "Incorrect value: first_name=#{first_name}!" unless Student.is_name?(first_name_value)
|
|
96
|
+
|
|
97
|
+
@first_name=first_name_value
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def middle_name=(middle_name_value)
|
|
101
|
+
raise ArgumentError, "Incorrect value: middle_name=#{middle_name}!" unless Student.is_name?(middle_name_value)
|
|
102
|
+
|
|
103
|
+
@middle_name=middle_name_value
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def surname=(surname_value)
|
|
107
|
+
raise ArgumentError, "Incorrect value: surname=#{surname}!" unless Student.is_name?(surname_value)
|
|
108
|
+
|
|
109
|
+
@surname=surname_value
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def git=(git_value)
|
|
113
|
+
raise ArgumentError, "Incorrect value: git=#{git}!" unless Student.is_git?(git_value)
|
|
114
|
+
|
|
115
|
+
@git=git_value
|
|
116
|
+
end
|
|
117
|
+
protected
|
|
118
|
+
def phone_number=(phone_number_value)
|
|
119
|
+
raise ArgumentError, "Incorrect value: phone_number=#{phone_number_value}!" unless Student.is_phone?(phone_number_value)
|
|
120
|
+
|
|
121
|
+
@phone_number=phone_number_value
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def mail=(mail_value)
|
|
125
|
+
raise ArgumentError, "Incorrect value: mail=#{mail}!" unless Student.is_mail?(mail_value)
|
|
126
|
+
|
|
127
|
+
@mail=mail_value
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def telegram=(telegram_value)
|
|
131
|
+
raise ArgumentError, "Incorrect value: telegram=#{telegram}!" unless Student.is_telegram?(telegram_value)
|
|
132
|
+
|
|
133
|
+
@telegram=telegram_value
|
|
134
|
+
end
|
|
135
|
+
public
|
|
136
|
+
|
|
137
|
+
def to_s
|
|
138
|
+
result = "#{first_name} #{middle_name} #{surname}"
|
|
139
|
+
result += " id=#{id}" unless id.nil?
|
|
140
|
+
result += " phone=#{phone_number}" unless phone_number.nil?
|
|
141
|
+
result += " git=#{git}" unless git.nil?
|
|
142
|
+
result += " telegram=#{telegram}" unless telegram.nil?
|
|
143
|
+
result += " mail=#{mail}" unless mail.nil?
|
|
144
|
+
result
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def contact
|
|
148
|
+
return @contact = "phone_number= #{phone_number}" unless phone_number.nil?
|
|
149
|
+
return @contact = "telegram= #{telegram}" unless telegram.nil?
|
|
150
|
+
return @contact = "mail= #{mail}" unless mail.nil?
|
|
151
|
+
|
|
152
|
+
nil
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
end
|
|
156
|
+
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
require_relative 'student'
|
|
3
|
+
class StudentShort
|
|
4
|
+
|
|
5
|
+
attr_reader :id,:surname,:short_name, :git, :contact
|
|
6
|
+
|
|
7
|
+
def initialize(student)
|
|
8
|
+
@id = student.id
|
|
9
|
+
@surname = student.surname
|
|
10
|
+
@short_name = "#{student.first_name[0]}. #{student.middle_name[0]}."
|
|
11
|
+
@git = student.git unless student.git.nil?
|
|
12
|
+
@contact = student.set_contacts(phone_number: student.phone_number, mail:student.mail,telegram: student.telegram)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.from_str(id,str)
|
|
16
|
+
res = JSON.parse(str)
|
|
17
|
+
|
|
18
|
+
Student_Short.new(Student.new(first_name: res['fisrst_name'],
|
|
19
|
+
middle_name:res['middle_name'], surname:res['surname'], id:id,
|
|
20
|
+
phone_number: result['phone_number'], git: result['git'],
|
|
21
|
+
mail: result['mail'],telegram: result['telegram']))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def to_s
|
|
25
|
+
res = short_name_initials
|
|
26
|
+
res += " id=#{id}" unless id.nil?
|
|
27
|
+
res += " git=#{git}" unless git.nil?
|
|
28
|
+
res += " #{contact}" unless contact.nil?
|
|
29
|
+
res
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def short_name_initials
|
|
33
|
+
"#{@surname} #{@short_name}"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
#валидатор
|
|
37
|
+
def validate?
|
|
38
|
+
exist_git? and exist_contact?
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def exist_git?
|
|
42
|
+
!self.git.nil?
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def exist_contact?
|
|
46
|
+
!(self.phone_number.nil? and self.telegram.nil? and self.mail.nil?)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
# frozen_string_literal: true
|
|
50
|
+
|