students_list_yaml_by_n312k 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 56a786c69cc0707ffe100812706d61d3e2065c34e4515e16fe46a0239d4584dd
4
+ data.tar.gz: 5bdcb7be15c94f8f67f7e41430c9053ce46c002f766d6260040a5005d3e5d5e5
5
+ SHA512:
6
+ metadata.gz: c5b15f339d0bf23523ce8e6cf02e61f84e83cb1694dc9ec6817124ec71114e9521a30f779ebc6faeac8d1e7b4ea72491bc4fb16f2413992c10ad5049b7d2c410
7
+ data.tar.gz: 2489690de487be66fb3729ab6a17d6f34a30c90a661c1db887c99cc379ef1c2a9572c0cae0688e78cf929d4927960a2a0e89685ca61c95b7ddc0372762cefa66
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Laboratory Work 4
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # StudentsListYaml
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/students_list_yaml`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ ```bash
14
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ ```bash
20
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/students_list_yaml.
@@ -0,0 +1,86 @@
1
+ require 'yaml'
2
+
3
+ module StudentsListYaml
4
+ class StudentsListYAML
5
+
6
+ def initialize(file_path)
7
+ @file_path = file_path
8
+ @students = []
9
+ end
10
+
11
+ def read_all
12
+ return unless File.exist?(@file_path)
13
+ data = YAML.load_file(@file_path) || []
14
+ @students = data.map { |h| Student.new(**h.transform_keys(&:to_sym)) }
15
+ end
16
+
17
+ def write_all
18
+ data = @students.map(&:to_hash)
19
+ File.write(@file_path, YAML.dump(data))
20
+ end
21
+
22
+ def get_student_by_id(id)
23
+ @students.find { |s| s.id == id } || "Студент не найден"
24
+ end
25
+
26
+ def get_k_n_student_short_list(k, n, existing_data_list = nil)
27
+ slice = @students[n, k] || []
28
+ short_list = slice.map { |s| StudentShort.from_student(s) }
29
+ if existing_data_list
30
+ existing_data_list.elements = short_list
31
+ existing_data_list
32
+ else
33
+ DataListStudentShort.new(short_list)
34
+ end
35
+ end
36
+
37
+ def sort_by_initials
38
+ @students.sort_by! { |s| [s.last_name_initials || ""] }
39
+ end
40
+
41
+ def same?(new_student, exclude_id: nil)
42
+ @students.any? do |s|
43
+ next false if exclude_id && s.id == exclude_id
44
+ next true if s.git && new_student.git && s.git == new_student.git
45
+ [:phone, :telegram, :email].any? do |field|
46
+ s_value = s.instance_variable_get("@#{field}")
47
+ new_value = new_student.instance_variable_get("@#{field}")
48
+ s_value && new_value && s_value == new_value
49
+ end
50
+ end
51
+ end
52
+
53
+ def add_student(student)
54
+ raise ArgumentError, "Контакты студента не уникальны" if same?(student)
55
+ max_id = (@students.map(&:id).max || 0)
56
+ student_with_id = Student.new(**student.to_hash.merge(id: max_id + 1))
57
+ @students << student_with_id
58
+ student_with_id
59
+ end
60
+
61
+ def update_student(id, new_attributes)
62
+ student = get_student_by_id(id)
63
+ raise ArgumentError, "Студент с ID #{id} не найден" unless student
64
+ new_attributes.each do |attr, value|
65
+ setter = "#{attr}="
66
+ if student.respond_to?(setter)
67
+ student.send(setter, value)
68
+ else
69
+ raise ArgumentError, "Неверный атрибут #{attr}"
70
+ end
71
+ end
72
+ raise ArgumentError, "Обновление нарушает уникальность" if same?(student, exclude_id: id)
73
+ student
74
+ end
75
+
76
+ def delete_student(id)
77
+ @students.reject! { |s| s.id == id }
78
+ end
79
+
80
+ def get_student_short_count
81
+ @students.size
82
+ end
83
+
84
+ end
85
+
86
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StudentsListYaml
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "students_list_yaml/version"
4
+ require_relative "students_list_yaml/students_list_yaml_by_n312k"
5
+
6
+ module StudentsListYaml
7
+ class Error < StandardError; end
8
+ # Your code goes here...
9
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: students_list_yaml_by_n312k
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - N312k
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2026-01-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Гем для работы с классами Student и StudentsListYAML через YAML файлы
14
+ email:
15
+ - ntashirov18@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE.txt
21
+ - README.md
22
+ - lib/students_list_yaml/students_list_yaml_by_n312k.rb
23
+ - lib/students_list_yaml/version.rb
24
+ - lib/students_list_yaml_by_n312k.rb
25
+ homepage:
26
+ licenses: []
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 3.0.0
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubygems_version: 3.3.5
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Работа со студентами через YAML
47
+ test_files: []