YAML_file_ops 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: 525de889e6d1e4e54bec3c54728247e9ebd0f5928203a694fc17d00b656aeca9
4
+ data.tar.gz: 2839f4e58a44c1de884e394d819abf1bcccbc4b7bc341abc109e7d8ec887d7cc
5
+ SHA512:
6
+ metadata.gz: 4e32f30b96fcd29f113573325742d7ad7b4b6c28cd36786dcffc64eae2d797963af02da6405e95fdf9cc924bdc3b4f9b16fa0758209302dfc172813629718153
7
+ data.tar.gz: 6cd44e6c37e94929647f04500e22096a9c884da9fa776ca49b3bd9a9b64a1f95c84f5a63934dc1c364f7627a5f33e6f5442c33ce9ac29894af85f049a768c72c
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Ower
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/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # YAMLFileOps
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/YAML_file_ops`. 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]/YAML_file_ops.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,50 @@
1
+ require_relative './DataTable.rb'
2
+
3
+ class Data_list
4
+
5
+ def initialize(objects)
6
+ @objects = objects
7
+ end
8
+
9
+ def select(number)
10
+ return @objects[number]
11
+ end
12
+
13
+ def get_selected(array)
14
+ id_array = []
15
+
16
+ for i in array
17
+ id_array.append(@objects.index(i) + 1)
18
+ end
19
+
20
+ return id_array
21
+ end
22
+
23
+ def get_names()
24
+ return ["№ По порядку"] + name_feature()
25
+ end
26
+
27
+ def get_data()
28
+
29
+ table = []
30
+
31
+ for i in 0...@objects.length
32
+ table.append([(i + 1).to_s] + data_feature(i))
33
+ end
34
+
35
+ return Data_table.new(table)
36
+ end
37
+
38
+ def clear_selected()
39
+ @objects = []
40
+ end
41
+
42
+ private def name_feature(i)
43
+ raise NotImplementError
44
+ end
45
+
46
+ private def data_feature()
47
+ raise NotImplementError
48
+ end
49
+
50
+ end
@@ -0,0 +1,19 @@
1
+ require_relative './DataList.rb'
2
+
3
+ class Data_list_student_short < Data_list
4
+
5
+ attr_writer :objects
6
+
7
+ private def name_feature()
8
+ return ["Фамилия и инициалы", "Контакт", "Гит"]
9
+ end
10
+
11
+ private def data_feature(i)
12
+ return [@objects[i].last_name_initials, @objects[i].contact, @objects[i].git]
13
+ end
14
+
15
+ end
16
+
17
+
18
+
19
+
@@ -0,0 +1,19 @@
1
+ class Data_table
2
+
3
+ def initialize(table)
4
+ @table = table
5
+ end
6
+
7
+ def element(x, y)
8
+ return @table[x][y]
9
+ end
10
+
11
+ def rows()
12
+ return @table.length
13
+ end
14
+
15
+ def columns()
16
+ return @table[0].length
17
+ end
18
+
19
+ end
@@ -0,0 +1,34 @@
1
+ class StudentSuper
2
+
3
+ attr_reader :id, :git
4
+
5
+ def has_git?()
6
+ return git != nil
7
+ end
8
+
9
+ def has_contact?()
10
+ return contact != nil
11
+ end
12
+
13
+
14
+ def to_s()
15
+ return "#{id} #{feature_method} #{git}".strip
16
+ end
17
+
18
+ def short_info()
19
+ return ("#{last_name_initials} #{id} #{contact} #{git}".squeeze(" ")).strip
20
+ end
21
+
22
+ private def feature_method()
23
+ raise NotImplementedError
24
+ end
25
+
26
+ private def last_name_initials()
27
+ raise NotImplementedError
28
+ end
29
+
30
+ private def contact()
31
+ raise NotImplementedError
32
+ end
33
+
34
+ end
@@ -0,0 +1,93 @@
1
+ require_relative './DataListStudentShort.rb'
2
+ require_relative './DataTable.rb'
3
+ require_relative './student.rb'
4
+
5
+ class Student_list_file
6
+
7
+ def initialize(path)
8
+ @path = path
9
+ @objects = []
10
+ end
11
+
12
+ def read_file()
13
+ raise NotImplementedError
14
+ end
15
+
16
+ def write_file()
17
+ raise NotImplementedError
18
+ end
19
+
20
+ def get_object(id)
21
+ for i in @objects
22
+ if i.id == id
23
+ return i
24
+ end
25
+ end
26
+ end
27
+
28
+ def get_k_n_student_short_list (k, n)
29
+ shift = @objects.length / n
30
+ output = []
31
+
32
+ for i in (n * k)...(n * k + shift)
33
+ if (i < @objects.length)
34
+ output.append(Student.from_row(@objects[i]))
35
+ else
36
+ return Data_list_student_short.new(output)
37
+ end
38
+ end
39
+
40
+ return Data_list_student_short.new(output)
41
+
42
+ end
43
+
44
+ def sort_last_name_initials()
45
+ @objects = @objects.sort_by(){|obj| obj.last_name_initials}
46
+ end
47
+
48
+ def append(object)
49
+ for i in @objects
50
+ if i.is_similar?(object)
51
+ raise ArgumentError, "Обнаружено совпадение контакта"
52
+ end
53
+ end
54
+
55
+ max_id_obj = (@objects.max_by(){|obj| obj.id})
56
+
57
+ if max_id_obj.nil?
58
+ id = -1
59
+ else
60
+ id = max_id_obj.id
61
+ end
62
+
63
+ hash = object.get_hash()
64
+ hash[:id] = id + 1
65
+ @objects.append(Student.from_hash(hash))
66
+ end
67
+
68
+ def set_object(id, object)
69
+
70
+ object = (object.get_hash).values
71
+
72
+ object.delete_at(3)
73
+ object.unshift(id)
74
+
75
+ for i in 0...@objects.length
76
+ if (@objects[i].id == id)
77
+ @objects[i] = Student.from_row(object)
78
+ end
79
+ end
80
+ end
81
+
82
+ def delete_object(id)
83
+ for i in @objects
84
+ if (i.id == id)
85
+ @objects.delete(i)
86
+ end
87
+ end
88
+ end
89
+
90
+ def get_student_short_count()
91
+ return @objects.length
92
+ end
93
+ end
@@ -0,0 +1,157 @@
1
+ require_relative './StudentSuper.rb'
2
+
3
+ class Student < StudentSuper
4
+ include Comparable
5
+
6
+ attr_reader :last_name, :first_name, :patronymic
7
+
8
+ def initialize(last_name:, first_name:, patronymic: nil, id: nil, phone: nil, telegram: nil, email: nil, git: nil)
9
+
10
+ self.last_name = last_name
11
+ self.first_name = first_name
12
+
13
+ if patronymic.nil?
14
+ @patronymic = patronymic
15
+ else
16
+ self.patronymic = patronymic
17
+ end
18
+
19
+ @id = id
20
+ self.contact = {phone: phone, telegram: telegram, email: email}
21
+ self.git = git
22
+ end
23
+
24
+ def Student.from_hash(hash)
25
+ return new(last_name: hash[:last_name], first_name: hash[:first_name], patronymic: hash[:patronymic], id: hash[:id], phone: hash[:phone], telegram: hash[:telegram], email: hash[:email], git: hash[:git])
26
+ end
27
+
28
+ def Student.from_row(row)
29
+ return new(last_name: row[1], first_name: row[2], patronymic: row[3], id: row[0], phone: row[4], telegram: row[5], email: row[6], git: row[7])
30
+ end
31
+
32
+
33
+
34
+ #####
35
+
36
+ def contact()
37
+
38
+ if @telegram != nil
39
+ return "telegram - #{@telegram}"
40
+ end
41
+
42
+ if @email != nil
43
+ return "email - #{@email}"
44
+ end
45
+
46
+ if @phone != nil
47
+ return "phone - #{@phone}"
48
+ end
49
+
50
+ return nil
51
+
52
+ end
53
+
54
+ def contact=(contacts)
55
+
56
+ if not(Student.valid_phone?(contacts[:phone]))
57
+ raise ArgumentError, "Неверный формат номера"
58
+ end
59
+
60
+ if not(Student.valid_telegram?(contacts[:telegram]))
61
+ raise ArgumentError, "Неверный формат Телеграм"
62
+ end
63
+
64
+ if not(Student.valid_email?(contacts[:email]))
65
+ raise ArgumentError, "Неверный формат почты"
66
+ end
67
+
68
+
69
+
70
+ @phone = contacts[:phone]
71
+ @telegram = contacts[:telegram]
72
+ @email = contacts[:email]
73
+
74
+
75
+ end
76
+
77
+ #####
78
+
79
+ def self.create_validable_setters(field, validator, error_message)
80
+ define_method("#{field}=") do |value|
81
+ if (value.nil?) || self.class.send(validator, value)
82
+ instance_variable_set("@#{field}", value)
83
+ else
84
+ raise ArgumentError, "Неверный формат #{error_message}"
85
+ end
86
+ end
87
+ end
88
+
89
+ create_validable_setters :last_name, :valid_name?, "фамилии"
90
+ create_validable_setters :first_name, :valid_name?, "имени"
91
+ create_validable_setters :patronymic, :valid_name?, "отчества"
92
+ create_validable_setters :git, :valid_git?, "Гита"
93
+
94
+ #####
95
+
96
+ def self.valid_name?(input)
97
+ not(input.nil?) && input.match(/^[А-Я][а-я]*$/) || input.match(/^[A-Z][a-z]*$/)
98
+ end
99
+
100
+ def self.valid_phone?(input)
101
+ input.nil? || input.match(/^((\+7)|(8))\d{10}$/) || input.match(/^((\+7)|(8))\(\d{3}\)\d{3}-\d{2}-\d{2}$/)
102
+ end
103
+
104
+ def self.valid_telegram?(input)
105
+ input.nil? || input.match(/^@[0-9A-Za-z_]{5,32}$/)
106
+ end
107
+
108
+ def self.valid_email?(input)
109
+ input.nil? || input.match(/^[0-9A-Za-z+-_%.]+@[0-9A-Za-z_]+(\.[0-9A-Za-z_]+)+$/)
110
+ end
111
+
112
+ def self.valid_git?(input)
113
+ input.nil? || input.match(/^https:\/\/git((hub)|(lab)).com\/[0-9A-Za-z_-]+$/)
114
+ end
115
+
116
+ #####
117
+
118
+
119
+ #####
120
+
121
+ def last_name_initials()
122
+ initials = "#{@last_name} #{@first_name[0]}."
123
+
124
+ if @patronymic != nil
125
+ initials += " #{@patronymic[0]}."
126
+ end
127
+
128
+ return initials
129
+ end
130
+
131
+ #####
132
+
133
+ private def feature_method()
134
+ return ("#{@last_name} #{@first_name} #{@patronymic} #{@phone} #{@telegram} #{@email}".squeeze(" ")).strip
135
+ end
136
+
137
+ #####
138
+
139
+ def get_hash()
140
+ return {last_name: @last_name, first_name: @first_name, patronymic: @patronymic, id: @id, phone: @phone, telegram: @telegram, email: @email, git: @git}
141
+ end
142
+
143
+ #####
144
+
145
+ def <=>(thing)
146
+ first = self.last_name + self.first_name + "#{self.patronymic}"
147
+ last = thing.last_name + thing.first_name + "#{thing.patronymic}"
148
+
149
+ return first <=> last
150
+ end
151
+
152
+ end
153
+
154
+
155
+
156
+
157
+
@@ -0,0 +1,31 @@
1
+ require_relative './StudentSuper.rb'
2
+
3
+ class StudentShort < StudentSuper
4
+
5
+ attr_reader :last_name_initials, :contact
6
+
7
+ def initialize(id:, last_name_initials:, contact: nil, git: nil)
8
+
9
+ @id = id
10
+ @last_name_initials = last_name_initials
11
+ @contact = contact
12
+ @git = git
13
+
14
+ end
15
+
16
+ def StudentShort.from_student(student)
17
+ new(id: student::id, last_name_initials: student::last_name_initials, contact: student::contact, git: student::git)
18
+ end
19
+
20
+ #####
21
+
22
+ private def feature_method()
23
+ return "#{@last_name_initials} #{@contact}".strip
24
+ end
25
+
26
+ #####
27
+
28
+
29
+
30
+
31
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YAMLFileOps
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'YAML_file_ops/DataListStudentShort.rb'
4
+ require 'YAML_file_ops/Student_list_file.rb'
5
+ require 'YAML_file_ops/student.rb'
6
+ require 'yaml/store'
7
+ require 'yaml'
8
+
9
+ require_relative "YAML_file_ops/version"
10
+
11
+ module YAMLFileOps
12
+ class Error < StandardError; end
13
+
14
+ class Student_list_YAML < Student_list_file
15
+
16
+ def initialize(path)
17
+ super
18
+
19
+ @store = YAML::Store.new(@path)
20
+ end
21
+
22
+ def read_file()
23
+
24
+ @store.transaction do
25
+ for i in @store.roots
26
+ @objects.append(@store[i])
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ def write_file()
33
+
34
+ @store.transaction do
35
+ for i in @objects
36
+ @store[i.id] = i
37
+ end
38
+ end
39
+
40
+ end
41
+
42
+
43
+
44
+ end
45
+
46
+
47
+ end
@@ -0,0 +1,4 @@
1
+ module YAMLFileOps
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: YAML_file_ops
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ower
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2026-01-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: For study
14
+ email:
15
+ - vcevolod13101985@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE.txt
21
+ - README.md
22
+ - Rakefile
23
+ - lib/YAML_file_ops.rb
24
+ - lib/YAML_file_ops/DataList.rb
25
+ - lib/YAML_file_ops/DataListStudentShort.rb
26
+ - lib/YAML_file_ops/DataTable.rb
27
+ - lib/YAML_file_ops/StudentSuper.rb
28
+ - lib/YAML_file_ops/Student_list_file.rb
29
+ - lib/YAML_file_ops/student.rb
30
+ - lib/YAML_file_ops/student_short.rb
31
+ - lib/YAML_file_ops/version.rb
32
+ - sig/YAML_file_ops.rbs
33
+ homepage:
34
+ licenses:
35
+ - MIT
36
+ metadata: {}
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 3.2.0
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubygems_version: 3.5.3
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: For study
56
+ test_files: []