mc_gem 0.0.1

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.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +12 -0
  3. data/Gemfile.lock +91 -0
  4. data/Lab1/arr1_3.txt +1 -0
  5. data/Lab1/lb1_1.rb +19 -0
  6. data/Lab1/lb1_2.rb +28 -0
  7. data/Lab1/lb1_3.rb +46 -0
  8. data/Lab1/lb1_4.rb +82 -0
  9. data/Lab2/1Class.jpg +0 -0
  10. data/Lab2/Web/main.rb +89 -0
  11. data/Lab2/Web/views/add.html +168 -0
  12. data/Lab2/Web/views/main.html +233 -0
  13. data/Lab2/data_storage/students1.txt +1 -0
  14. data/Lab2/data_storage/studentsRead.json +36 -0
  15. data/Lab2/data_storage/studentsRead.txt +3 -0
  16. data/Lab2/data_storage/studentsRead.yaml +26 -0
  17. data/Lab2/data_storage/studentsWrite.json +42 -0
  18. data/Lab2/data_storage/studentsWrite.txt +4 -0
  19. data/Lab2/data_storage/studentsWrite.yaml +31 -0
  20. data/Lab2/examples/Strategy.rb +38 -0
  21. data/Lab2/examples/adapter.rb +30 -0
  22. data/Lab2/examples/database.rb +15 -0
  23. data/Lab2/examples/observer_example.rb +51 -0
  24. data/Lab2/examples/pattern_pattern.rb +44 -0
  25. data/Lab2/examples/site_example.rb +21 -0
  26. data/Lab2/examples/views/about.erb +11 -0
  27. data/Lab2/examples/views/contact.erb +15 -0
  28. data/Lab2/examples/views/index.erb +11 -0
  29. data/Lab2/main.rb +6 -0
  30. data/Lab2/main_window.rb +31 -0
  31. data/Lab2/student_input_form.rb +71 -0
  32. data/Lab2/tab_students.rb +157 -0
  33. data/Lab2/test/student_test.rb +91 -0
  34. data/README.md +3 -0
  35. data/mc_gem/CHANGELOG.md +5 -0
  36. data/mc_gem/CODE_OF_CONDUCT.md +84 -0
  37. data/mc_gem/Documentation.md +33 -0
  38. data/mc_gem/Gemfile +13 -0
  39. data/mc_gem/LICENSE.txt +21 -0
  40. data/mc_gem/README.md +1 -0
  41. data/mc_gem/lib/mc_gem/version.rb +5 -0
  42. data/mc_gem/lib/mc_gem.rb +10 -0
  43. data/mc_gem/lib/source/adapters/student_list_adapter.rb +95 -0
  44. data/mc_gem/lib/source/containers/Data_list.rb +66 -0
  45. data/mc_gem/lib/source/containers/Data_list_student_short.rb +17 -0
  46. data/mc_gem/lib/source/containers/Data_table.rb +25 -0
  47. data/mc_gem/lib/source/controllers/student_edit_form_controller.rb +63 -0
  48. data/mc_gem/lib/source/controllers/student_input_form_controller.rb +56 -0
  49. data/mc_gem/lib/source/controllers/student_list_controller.rb +83 -0
  50. data/mc_gem/lib/source/converters/Converter.rb +11 -0
  51. data/mc_gem/lib/source/converters/Converter_json.rb +14 -0
  52. data/mc_gem/lib/source/converters/Converter_txt.rb +26 -0
  53. data/mc_gem/lib/source/converters/Converter_yaml.rb +14 -0
  54. data/mc_gem/lib/source/database/scripts/create_table.sql +10 -0
  55. data/mc_gem/lib/source/database/scripts/insert_data.sql +4 -0
  56. data/mc_gem/lib/source/database/student_list_db.rb +41 -0
  57. data/mc_gem/lib/source/database/students_db.rb +79 -0
  58. data/mc_gem/lib/source/model/Student.rb +106 -0
  59. data/mc_gem/lib/source/model/StudentBase.rb +50 -0
  60. data/mc_gem/lib/source/model/Student_short.rb +39 -0
  61. data/mc_gem/lib/source/repositories/Student_list.rb +65 -0
  62. data/mc_gem/lib/source/repositories/student_list_adv.rb +35 -0
  63. data/mc_gem/lib/source/util/LoggerHolder.rb +22 -0
  64. data/mc_gem/mc_gem.gemspec +17 -0
  65. data/mc_gem/sig/mvcStudentXD.rbs +4 -0
  66. metadata +121 -0
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'glimmer-dsl-libui'
4
+ require_relative '../mc_gem/lib/source/controllers/student_input_form_controller'
5
+ require_relative '../mc_gem/lib/source/model/StudentBase'
6
+ require 'win32api'
7
+
8
+ class StudentInputForm
9
+ include Glimmer
10
+
11
+ def initialize(controller,existing_student = nil)
12
+ @existing_student = existing_student.to_hash unless existing_student.nil?
13
+ @controller = controller
14
+ @entries = {}
15
+ end
16
+
17
+ def on_create
18
+ @controller.on_view_created
19
+ end
20
+
21
+ def create
22
+ @root_container = window('Универ', 300, 150) {
23
+ resizable false
24
+
25
+ vertical_box {
26
+ @student_form = form {
27
+ stretchy false
28
+
29
+ fields = [[:last_name, 'Фамилия', false], [:first_name, 'Имя', false], [:parental_name, 'Отчество', false], [:git, 'Гит', true], [:telegram, 'Телеграм', true], [:email, 'Почта', true], [:phone, 'Телефон', true]]
30
+
31
+ fields.each do |field|
32
+ @entries[field[0]] = entry {
33
+ label field[1]
34
+ text @existing_student[field[0]] unless @existing_student.nil?
35
+
36
+ read_only field[2] unless @existing_student.nil?
37
+ }
38
+ end
39
+ }
40
+
41
+ button('Сохранить') {
42
+ stretchy false
43
+
44
+ on_clicked {
45
+ values = @entries.transform_values { |v| v.text.force_encoding("utf-8").strip }
46
+ values.transform_values! { |v| v.empty? ? nil : v}
47
+ @controller.process_fields(values)
48
+ @controller.refresh
49
+ }
50
+ }
51
+ }
52
+ }
53
+ on_create
54
+ @root_container
55
+ end
56
+
57
+ def set_value(field, value)
58
+ return unless @entries.include?(field)
59
+ @entries[field].text = value
60
+ end
61
+
62
+ def make_readonly(*fields)
63
+ fields.each do |field|
64
+ @entries[field].read_only = true
65
+ end
66
+ end
67
+
68
+ def close
69
+ @root_container.destroy
70
+ end
71
+ end
@@ -0,0 +1,157 @@
1
+ # frozen_string_literal: true
2
+
3
+ # frozen_string_literal: true
4
+ require 'glimmer-dsl-libui'
5
+ require_relative '../mc_gem/lib/source/controllers/student_list_controller'
6
+ require_relative '../mc_gem/lib/source/database/students_db'
7
+
8
+ class TabStudents
9
+ include Glimmer
10
+ STUDENTS_PER_PAGE = 20
11
+
12
+ def initialize
13
+ @controller = StudentListController.new(self)
14
+ @current_page = 1
15
+ @total_count = 0
16
+ end
17
+
18
+ def on_create
19
+ @controller.on_view_created
20
+ @controller.refresh_data(@current_page, STUDENTS_PER_PAGE)
21
+ end
22
+
23
+ # Метод наблюдателя datalist
24
+ def on_datalist_changed(new_table)
25
+ arr = new_table.to_2d_array
26
+ @table.model_array = arr
27
+ end
28
+
29
+ def update_student_count(new_cnt)
30
+ @total_count = new_cnt
31
+ @page_label.text = "#{@current_page} / #{(@total_count / STUDENTS_PER_PAGE.to_f).ceil}"
32
+ end
33
+
34
+ def create
35
+ root = horizontal_box {
36
+ # Секция 1
37
+ vertical_box {
38
+ stretchy false
39
+
40
+ form {
41
+ stretchy false
42
+
43
+ @filter_last_name_initials = entry {
44
+ label 'ФИО'
45
+ }
46
+
47
+ @filters = {}
48
+ fields = [[:git, 'Github'], [:email, 'Почта'], [:phone, 'Телефон'], [:telegram, 'Телеграм']]
49
+
50
+ fields.each do |field|
51
+ @filters[field[0]] = {}
52
+
53
+ @filters[field[0]][:combobox] = combobox {
54
+ label "#{field[1]}?"
55
+ items ['Не важно', 'Есть', 'Нет']
56
+ selected 0
57
+
58
+ on_selected do
59
+ if @filters[field[0]][:combobox].selected == 1
60
+ @filters[field[0]][:entry].read_only = false
61
+ else
62
+ @filters[field[0]][:entry].text = ''
63
+ @filters[field[0]][:entry].read_only = true
64
+ end
65
+ end
66
+ }
67
+
68
+ @filters[field[0]][:entry] = entry {
69
+ label field[1]
70
+ read_only true
71
+ }
72
+ end
73
+ }
74
+ }
75
+
76
+ # Секция 2
77
+ vertical_box {
78
+ @table = refined_table(
79
+ table_editable: false,
80
+ filter: lambda do |row_hash, query|
81
+ utf8_query = query.force_encoding("utf-8")
82
+ row_hash['Фамилия И. О'].include?(utf8_query)
83
+ end,
84
+ table_columns: {
85
+ '#' => :text,
86
+ 'Фамилия И. О' => :text,
87
+ 'Гит' => :text,
88
+ 'Контакт' => :text,
89
+ },
90
+ per_page: STUDENTS_PER_PAGE
91
+ )
92
+
93
+ @pages = horizontal_box {
94
+ stretchy false
95
+
96
+ button("<") { stretchy true }
97
+ button("<") {
98
+ stretchy true
99
+
100
+ on_clicked do
101
+ @current_page = [@current_page - 1, 1].max
102
+ @controller.refresh_data(@current_page, STUDENTS_PER_PAGE)
103
+ end
104
+
105
+ }
106
+ @page_label = label("...") { stretchy false }
107
+ button(">") { stretchy true }
108
+ button(">") {
109
+ stretchy true
110
+
111
+ on_clicked do
112
+ @current_page = [@current_page + 1, (@total_count / STUDENTS_PER_PAGE.to_f).ceil].min
113
+ @controller.refresh_data(@current_page, STUDENTS_PER_PAGE)
114
+ end
115
+ }
116
+ }
117
+ }
118
+
119
+ # Секция 3
120
+ vertical_box {
121
+ stretchy true
122
+
123
+ button('Добавить') {
124
+ stretchy false
125
+
126
+ on_clicked {
127
+ @controller.show_modal_add()
128
+ }
129
+ }
130
+ button('Изменить') {
131
+ stretchy false
132
+
133
+ on_clicked {
134
+ @controller.show_modal_edit(@current_page, STUDENTS_PER_PAGE, @table.selection) unless @table.selection.nil?
135
+ }
136
+ }
137
+ button('Удалить') {
138
+ stretchy false
139
+
140
+ on_clicked {
141
+ @controller.delete_selected(@current_page, STUDENTS_PER_PAGE, @table.selection) unless @table.selection.nil?
142
+ @controller.refresh_data(@current_page, STUDENTS_PER_PAGE)
143
+ }
144
+ }
145
+ button('Обновить') {
146
+ stretchy false
147
+ on_clicked{
148
+ @controller.refresh_data(@current_page, STUDENTS_PER_PAGE)
149
+ }
150
+ }
151
+ }
152
+ }
153
+ on_create
154
+ root
155
+ end
156
+
157
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+ require 'minitest/autorun'
3
+ require 'json'
4
+ require_relative '../../mc_gem/lib/mc_gem'
5
+
6
+ class StudentTest < Minitest::Test
7
+ def setup
8
+ @student = Student.new(
9
+ 'Лукашев',
10
+ 'Алексей',
11
+ 'Андреевич',
12
+ id: 10,
13
+ phone: '89099997499',
14
+ telegram: '@lehadrilla',
15
+ email: 'leha@gmail.com',
16
+ git: '@netuOnNeftyanik'
17
+ )
18
+ end
19
+
20
+ def teardown
21
+ # Do nothing
22
+ end
23
+
24
+ def test_student_init_all_params_correct
25
+ assert @student.last_name == 'Лукашев'
26
+ assert @student.first_name == 'Алексей'
27
+ assert @student.parental_name == 'Андреевич'
28
+ assert @student.id == 10
29
+ assert @student.phone == '89099997499'
30
+ assert @student.telegram == '@lehadrilla'
31
+ assert @student.email == 'leha@gmail.com'
32
+ assert @student.git == '@netuOnNeftyanik'
33
+ end
34
+
35
+ def test_student_empty_options
36
+ Student.new('Сергеев', 'Сергей', 'Сергеевич')
37
+ end
38
+
39
+ def test_student_short_contact
40
+ short_contact = @student.get_short_contact
41
+
42
+
43
+ assert short_contact[:type] == :telegram
44
+ assert short_contact[:val] == '@lehadrilla'
45
+ end
46
+
47
+ def test_student_has_contacts
48
+ assert @student.valid_cont? == true
49
+ end
50
+
51
+ def test_student_set_contacts
52
+ stud = Student.new('Орфов', 'Орф', 'Орфович')
53
+ stud.set_contacts(phone: '89097768999', telegram: '@kasha', email: 'kasha@gmail.com')
54
+
55
+ assert stud.phone == '89097768999'
56
+ assert stud.telegram == '@kasha'
57
+ assert stud.email == 'kasha@gmail.com'
58
+ end
59
+
60
+ def test_student_get_short_fio
61
+ assert @student.get_short_fio == 'fio:Лукашев А. А.'
62
+ end
63
+
64
+
65
+ def test_student_from_and_to_hash
66
+ test_hash = {
67
+ last_name: 'Жанов',
68
+ first_name: 'Жан',
69
+ parental_name: 'Жанович',
70
+ id: 5,
71
+ phone: '87776665544',
72
+ telegram: '@abv',
73
+ email: 'abv@mail.ru',
74
+ git: '@abvG'
75
+ }
76
+
77
+
78
+ stud = Student.from_hash(test_hash)
79
+
80
+ assert stud.last_name == 'Жанов'
81
+ assert stud.first_name == 'Жан'
82
+ assert stud.parental_name == 'Жанович'
83
+ assert stud.id == 5
84
+ assert stud.phone == '87776665544'
85
+ assert stud.telegram == '@abv'
86
+ assert stud.email == 'abv@mail.ru'
87
+ assert stud.git == '@abvG'
88
+
89
+ assert stud.to_hash == test_hash
90
+ end
91
+ end
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # RubyLabs
2
+ https://disk.yandex.ru/d/-5YnxFGCRloVRw/Лекции
3
+
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-04-28
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at delta.null@vk.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
@@ -0,0 +1,33 @@
1
+ The TabStudentsController class is a controller for working with the interface for interacting with objects of the Student type.
2
+
3
+ Methods of the class:
4
+
5
+ 1. initialize(view) - constructor of the class, takes a view object and creates an empty object of the type
6
+ DataListStudentShort, which is assigned the add_listener method with the view argument, as a result of which the view
7
+ is set as a listener for data state change events (data_list).
8
+ 2. on_view_created is a method that initializes an object of the StudentRepository type, which is used for interaction
9
+ with the database, and if an error occurs connecting to the database displays a dialog box with an error message.
10
+ 3. show_view is a method that displays the main application window.
11
+ 4. show_modal_add is a method that displays a modal window for creating a new student record.
12
+ Creates an instance of the StudentInputFormControllerCreate controller and passes it a reference to the current controller,
13
+ creates an object of the StudentInputForm type and passes it a reference to the controller. Then it displays the modal window.
14
+ 5. show_modal_edit(current_page, per_page, selected_row) is a method that displays the modal window for
15
+ editing a student record. Takes the values of the current page (current_page), the number of records on the page
16
+ (per_page) and the selected row (selected_row). Calculates the number of the selected student and selects his id from
17
+ the DataListStudentShort object, then passes it to the StudentInputFormControllerEdit controller, creates an object of the type
18
+ StudentInputForm and passes it a link to the controller. After that, it displays a modal window.
19
+ 6. delete_selected(current_page, per_page, selected_row) is a method that deletes the selected student record.
20
+ Takes the values of the current page (current_page), the number of records on the page (per_page)
21
+ and the selected row (selected_row). Calculates the number of the selected student and selects his id from the DataListStudentShort object,
22
+ then deletes the record using the remove_student method from the StudentRepository object.
23
+ 7. refresh_data(page, per_page) is a method that updates the data in the list of students. Takes the values
24
+ of the current page (page) and the number of entries on the page (per_page).
25
+ Calls a method of the StudentRepository paginated_short_students type to get data in the DataListStudentShort object format.
26
+ Updates information about the number of students using the update_student_count method of the view.
27
+
28
+ The Student_Input_Form_Controller_Edit controller and Student_Input_Form_Controller_Create are forms
29
+ for modifying and creating students into the database, respectively.
30
+
31
+ The student, student_base and student_short models are a student model with various fields and methods
32
+ for setting, receiving and processing information. Student_base - super class,
33
+ and student_short is the short information about the student.
data/mc_gem/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "mysql2"
6
+ gem "glimmer-dsl-libui",'~> 0.7.4'
7
+ gem 'win32api'
8
+ gem "minitest"
9
+ gem 'rubocop', group: 'development'
10
+ gem 'mvcStudentXD', '~> 1.2.2'
11
+ gem 'sinatra', '~> 3.0', '>= 3.0.6'
12
+ gem 'thin', '~> 1.8', '>= 1.8.2'
13
+ gem 'mc_delta'
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 NullExp
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/mc_gem/README.md ADDED
@@ -0,0 +1 @@
1
+ ![9bm](https://user-images.githubusercontent.com/96076243/218162066-5df24062-497f-4d8b-a9b2-5612afd68f07.gif)
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mc_Gem
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "mc_gem/version"
4
+
5
+ module Mc_Gem
6
+ Dir[File.dirname(__FILE__) + '/source/**/*.rb'].each { |file|
7
+ puts file
8
+ require file
9
+ }
10
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+ require_relative '../repositories/Student_list'
3
+ class StudentsListAdapter
4
+ private_class_method :new
5
+ def get_student(id)
6
+ end
7
+
8
+ def remove_student(id)
9
+ end
10
+
11
+ def replace_student(id, student)
12
+ end
13
+
14
+ def get_students_pag(k, n, data)
15
+ end
16
+
17
+ def add_student(student)
18
+ end
19
+
20
+ def count
21
+ end
22
+ end
23
+
24
+ class StudentsListDBAdapter < StudentsListAdapter
25
+ private
26
+ attr_accessor :database_list
27
+
28
+ public_class_method :new
29
+
30
+ public
31
+ def initialize(database_list)
32
+ self.database_list = database_list
33
+ end
34
+
35
+ def get_student(id)
36
+ database_list.get_student(id)
37
+ end
38
+
39
+ def remove_student(id)
40
+ database_list.remove_student(id)
41
+ end
42
+
43
+ def replace_student(id, student)
44
+ database_list.replace_student(id, student)
45
+ end
46
+
47
+ def get_students_pag(from, to, data)
48
+ database_list.get_students_pag(from, to, data)
49
+ end
50
+
51
+ def add_student(student)
52
+ database_list.add_student(student)
53
+ end
54
+
55
+ def count
56
+ database_list.count
57
+ end
58
+ end
59
+
60
+ class StudentsListConverterAdapter < StudentsListAdapter
61
+ private
62
+ attr_accessor :file_list
63
+
64
+ public_class_method :new
65
+
66
+ public
67
+ def initialize(file_list, filename)
68
+ self.file_list = file_list
69
+ self.file_list.read_file(filename)
70
+ end
71
+
72
+ def get_student(id)
73
+ file_list.get_student(id)
74
+ end
75
+
76
+ def remove_student(id)
77
+ file_list.remove_student(id)
78
+ end
79
+
80
+ def replace_student(id, student)
81
+ file_list.replace_student(id, student)
82
+ end
83
+
84
+ def get_students_pag(k, n, data=nil)
85
+ file_list.get_students_pag(k, n, data)
86
+ end
87
+
88
+ def add_student(student)
89
+ file_list.add_student(student)
90
+ end
91
+
92
+ def count
93
+ file_list.count
94
+ end
95
+ end
@@ -0,0 +1,66 @@
1
+ class DataList
2
+ private_class_method :new
3
+
4
+ attr_accessor :selected_num, :objects
5
+
6
+ def initialize(*elems)
7
+ self.objects = elems
8
+ @listeners = []
9
+ end
10
+
11
+ def add_listener(listener)
12
+ @listeners << listener
13
+ end
14
+
15
+ def remove_listener(listener)
16
+ @listeners.delete(listener)
17
+ end
18
+
19
+ def notify
20
+ @listeners.each { |lst| lst.on_datalist_changed(data_table) }
21
+ end
22
+
23
+ def select_element(number)
24
+ self.selected_num = number < objects.size ? number : nil
25
+ end
26
+
27
+ def selected_id
28
+ objects[selected_num].id
29
+ end
30
+
31
+ def get_names
32
+ self.objects.first.instance_variables.map{|v| v.to_s[1..-1]}
33
+ end
34
+
35
+ def table_fields(_obj)
36
+ []
37
+ end
38
+
39
+ def data_table
40
+ result = []
41
+ counter = 0
42
+ objects.each do |obj|
43
+ row = []
44
+ row << counter
45
+ row.push(*table_fields(obj))
46
+ result << row
47
+ counter += 1
48
+ end
49
+ DataTable.new(result)
50
+ end
51
+
52
+ def append(new_data)
53
+ self.objects.append(new_data)
54
+ end
55
+
56
+ def replace_objects(objects)
57
+ self.objects = objects.dup
58
+ notify
59
+ end
60
+
61
+ private
62
+ def instance_variables_wout_id(object)
63
+ object.instance_variables.reject{|v| v.to_sym ==:@id}.map{|v| object.instance_variable_get(v)}
64
+ end
65
+
66
+ end
@@ -0,0 +1,17 @@
1
+ require_relative '../model/Student_short'
2
+ require_relative '../containers/Data_table'
3
+ require_relative 'Data_list'
4
+ class DataListStudentShort < DataList
5
+
6
+ public_class_method :new
7
+
8
+ def get_names
9
+ ['Фамилия И.О.','Гит','Контакт']
10
+ end
11
+
12
+
13
+ def table_fields(obj)
14
+ [obj.fio, obj.git, obj.contact]
15
+ end
16
+
17
+ end