mealib 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.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rubocop.yml +50 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +20 -0
  7. data/README.md +11 -0
  8. data/bin/console +14 -0
  9. data/bin/rails +13 -0
  10. data/bin/setup +8 -0
  11. data/config/initializers/core_ext/string.rb +62 -0
  12. data/lib/dry/errors.rb +77 -0
  13. data/lib/dry/rule.rb +69 -0
  14. data/lib/dry/rules/and.rb +11 -0
  15. data/lib/dry/rules/between.rb +18 -0
  16. data/lib/dry/rules/binary.rb +16 -0
  17. data/lib/dry/rules/collection.rb +16 -0
  18. data/lib/dry/rules/composite.rb +19 -0
  19. data/lib/dry/rules/equal.rb +18 -0
  20. data/lib/dry/rules/format.rb +18 -0
  21. data/lib/dry/rules/greater_than.rb +18 -0
  22. data/lib/dry/rules/greater_than_or_equal.rb +18 -0
  23. data/lib/dry/rules/included.rb +18 -0
  24. data/lib/dry/rules/length_between.rb +18 -0
  25. data/lib/dry/rules/length_equal.rb +18 -0
  26. data/lib/dry/rules/less_than.rb +18 -0
  27. data/lib/dry/rules/less_than_or_equal.rb +18 -0
  28. data/lib/dry/rules/max_length.rb +18 -0
  29. data/lib/dry/rules/min_length.rb +18 -0
  30. data/lib/dry/rules/not_equal.rb +18 -0
  31. data/lib/dry/rules/or.rb +13 -0
  32. data/lib/dry/rules/present.rb +21 -0
  33. data/lib/dry/rules/then.rb +13 -0
  34. data/lib/dry/rules_factory.rb +118 -0
  35. data/lib/dry/schema.rb +148 -0
  36. data/lib/mealib.rb +48 -0
  37. data/lib/mealib/abstract_serializer.rb +28 -0
  38. data/lib/mealib/dict.rb +26 -0
  39. data/lib/mealib/engine.rb +5 -0
  40. data/lib/mealib/fucker/name/first_name_ru_man.txt +64 -0
  41. data/lib/mealib/fucker/name/last_name_ru_man.txt +252 -0
  42. data/lib/mealib/fucker/name/name.rb +27 -0
  43. data/lib/mealib/fucker/name/sur_name_ru_man.txt +53 -0
  44. data/lib/mealib/geo/distance.rb +22 -0
  45. data/lib/mealib/token_generator.rb +7 -0
  46. data/lib/mealib/version.rb +3 -0
  47. data/mealib.gemspec +26 -0
  48. metadata +117 -0
@@ -0,0 +1,48 @@
1
+ # загружаем библиотечные классы
2
+ lambda do
3
+ lib_path = '%s/**/*.rb' % File.expand_path('../mealib', __FILE__)
4
+ # noinspection RubyResolve
5
+ Dir[lib_path].each { |f| require_relative f }
6
+
7
+ require_relative 'dry/errors'
8
+ require_relative 'dry/schema'
9
+ require_relative 'dry/rule'
10
+
11
+ require_relative 'dry/rules/binary'
12
+ require_relative 'dry/rules/composite'
13
+ require_relative 'dry/rules/between'
14
+ require_relative 'dry/rules/min_length'
15
+ require_relative 'dry/rules/greater_than'
16
+ require_relative 'dry/rules/not_equal'
17
+ require_relative 'dry/rules/less_than'
18
+ require_relative 'dry/rules/greater_than_or_equal'
19
+ require_relative 'dry/rules/collection'
20
+ require_relative 'dry/rules/length_between'
21
+ require_relative 'dry/rules/or'
22
+ require_relative 'dry/rules/and'
23
+ require_relative 'dry/rules/less_than_or_equal'
24
+ require_relative 'dry/rules/then'
25
+ require_relative 'dry/rules/format'
26
+ require_relative 'dry/rules/present'
27
+ require_relative 'dry/rules/length_equal'
28
+ require_relative 'dry/rules/included'
29
+ require_relative 'dry/rules/equal'
30
+ require_relative 'dry/rules/max_length'
31
+
32
+ require_relative 'dry/rules_factory'
33
+ end.call
34
+
35
+ # загружаем все классы из директории app
36
+ lambda do
37
+ lib_path = File.expand_path('../../app', __FILE__)
38
+ dir_names = %w[] # order matters!
39
+
40
+ dir_names.each do |dir|
41
+ dir_path = '%s/%s/**/*.rb' % [lib_path, dir]
42
+ # noinspection RubyResolve
43
+ Dir[dir_path].each { |f| require_relative f }
44
+ end
45
+ end.call
46
+
47
+ module Mealib
48
+ end
@@ -0,0 +1,28 @@
1
+ class AbstractSerializer
2
+
3
+ # extend ActionView::Helpers::NumberHelper
4
+ # extend ApplicationHelper
5
+
6
+ class << self
7
+
8
+ def serialize(model, attributes: available_attributes, opts: {})
9
+ @opts = opts
10
+ unknown_attributes = attributes - available_attributes
11
+
12
+ if unknown_attributes.present?
13
+ raise StandardError, sprintf('Unknown attributes: %s', unknown_attributes.join(', '))
14
+ end
15
+
16
+ attributes.each_with_object({}) { |attribute, result| result.merge!(send(attribute, model)) }
17
+ end
18
+
19
+ def available_attributes
20
+ []
21
+ end
22
+
23
+ def opts
24
+ @opts
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ # Базовый класс для словарей из Dicts.
2
+ #
3
+ class Dict
4
+ attr_reader :id, :index
5
+
6
+ def initialize(id, index)
7
+ @id = id
8
+ @index = index
9
+ end
10
+
11
+ def self.all
12
+ constants.select { |const| (const_get const).class != Array }.map { |const| const_get const } # пока я не добавил константы типа ALL, работала эта строка: constants.map { |const| const_get const }
13
+ end
14
+
15
+ def self.find(id)
16
+ all.select { |const| const.id == id.to_i }.first
17
+ end
18
+
19
+ def self.find_by_index(index)
20
+ all.select { |const| const.index == index }.first
21
+ end
22
+
23
+ def self.where(ids)
24
+ all.select { |const| ids.include?(const.id) }
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ module Mealib
2
+ class Engine < ::Rails::Engine
3
+ config.i18n.load_path += Dir[config.root.join('config', 'locales', '**','*.{yml}').to_s]
4
+ end
5
+ end
@@ -0,0 +1,64 @@
1
+ Александр
2
+ Алексей
3
+ Анатолий
4
+ Андрей
5
+ Антон
6
+ Арсен
7
+ Артем
8
+ Артур
9
+ Богдан
10
+ Борис
11
+ Вадим
12
+ Валентин
13
+ Валерий
14
+ Василий
15
+ Виктор
16
+ Виталий
17
+ Владимир
18
+ Владислав
19
+ Всеволод
20
+ Вячеслав
21
+ Геннадий
22
+ Георгий
23
+ Глеб
24
+ Григорий
25
+ Давид
26
+ Даниил
27
+ Денис
28
+ Дмитрий
29
+ Евгений
30
+ Егор
31
+ Иван
32
+ Игнат
33
+ Игорь
34
+ Илья
35
+ Кирилл
36
+ Константин
37
+ Лев
38
+ Леонид
39
+ Максим
40
+ Матвей
41
+ Михаил
42
+ Никита
43
+ Николай
44
+ Олег
45
+ Павел
46
+ Петр
47
+ Ринат
48
+ Родион
49
+ Роман
50
+ Ростислав
51
+ Руслан
52
+ Рустем
53
+ Святослав
54
+ Семен
55
+ Сергей
56
+ Станислав
57
+ Степан
58
+ Тимофей
59
+ Тимур
60
+ Федор
61
+ Филипп
62
+ Юрий
63
+ Ян
64
+ Ярослав
@@ -0,0 +1,252 @@
1
+ Смирнов
2
+ Иванов
3
+ Кузнецов
4
+ Соколов
5
+ Попов
6
+ Лебедев
7
+ Козлов
8
+ Новиков
9
+ Морозов
10
+ Петров
11
+ Волков
12
+ Соловьёв
13
+ Васильев
14
+ Зайцев
15
+ Павлов
16
+ Семёнов
17
+ Голубев
18
+ Виноградов
19
+ Богданов
20
+ Воробьёв
21
+ Фёдоров
22
+ Михайлов
23
+ Беляев
24
+ Тарасов
25
+ Белов
26
+ Комаров
27
+ Орлов
28
+ Киселёв
29
+ Макаров
30
+ Андреев
31
+ Ковалёв
32
+ Ильин
33
+ Гусев
34
+ Титов
35
+ Кузьмин
36
+ Кудрявцев
37
+ Кудинов
38
+ Крапортов
39
+ Баранов
40
+ Куликов
41
+ Алексеев
42
+ Степанов
43
+ Яковлев
44
+ Сорокин
45
+ Сергеев
46
+ Романов
47
+ Захаров
48
+ Борисов
49
+ Королёв
50
+ Герасимов
51
+ Пономарёв
52
+ Григорьев
53
+ Лазарев
54
+ Медведев
55
+ Ершов
56
+ Никитин
57
+ Соболев
58
+ Рябов
59
+ Поляков
60
+ Цветков
61
+ Данилов
62
+ Жуков
63
+ Фролов
64
+ Журавлёв
65
+ Николаев
66
+ Крылов
67
+ Максимов
68
+ Сидоров
69
+ Осипов
70
+ Белоусов
71
+ Федотов
72
+ Дорофеев
73
+ Егоров
74
+ Матвеев
75
+ Бобров
76
+ Дмитриев
77
+ Калинин
78
+ Анисимов
79
+ Петухов
80
+ Антонов
81
+ Тимофеев
82
+ Никифоров
83
+ Веселов
84
+ Филиппов
85
+ Марков
86
+ Большаков
87
+ Суханов
88
+ Миронов
89
+ Ширяев
90
+ Александров
91
+ Коновалов
92
+ Шестаков
93
+ Казаков
94
+ Ефимов
95
+ Денисов
96
+ Громов
97
+ Фомин
98
+ Давыдов
99
+ Мельников
100
+ Щербаков
101
+ Блинов
102
+ Колесников
103
+ Карпов
104
+ Афанасьев
105
+ Власов
106
+ Маслов
107
+ Исаков
108
+ Тихонов
109
+ Аксёнов
110
+ Гаврилов
111
+ Родионов
112
+ Котов
113
+ Горбунов
114
+ Кудряшов
115
+ Быков
116
+ Зуев
117
+ Третьяков
118
+ Савельев
119
+ Панов
120
+ Рыбаков
121
+ Суворов
122
+ Абрамов
123
+ Воронов
124
+ Мухин
125
+ Архипов
126
+ Трофимов
127
+ Мартынов
128
+ Емельянов
129
+ Горшков
130
+ Чернов
131
+ Овчинников
132
+ Селезнёв
133
+ Панфилов
134
+ Копылов
135
+ Михеев
136
+ Галкин
137
+ Назаров
138
+ Лобанов
139
+ Лукин
140
+ Беляков
141
+ Потапов
142
+ Некрасов
143
+ Хохлов
144
+ Жданов
145
+ Наумов
146
+ Шилов
147
+ Воронцов
148
+ Ермаков
149
+ Дроздов
150
+ Игнатьев
151
+ Савин
152
+ Логинов
153
+ Сафонов
154
+ Капустин
155
+ Кириллов
156
+ Моисеев
157
+ Елисеев
158
+ Кошелев
159
+ Костин
160
+ Горбачёв
161
+ Орехов
162
+ Ефремов
163
+ Исаев
164
+ Евдокимов
165
+ Калашников
166
+ Кабанов
167
+ Носков
168
+ Юдин
169
+ Кулагин
170
+ Лапин
171
+ Прохоров
172
+ Нестеров
173
+ Харитонов
174
+ Агафонов
175
+ Муравьёв
176
+ Ларионов
177
+ Федосеев
178
+ Зимин
179
+ Пахомов
180
+ Шубин
181
+ Игнатов
182
+ Филатов
183
+ Крюков
184
+ Рогов
185
+ Кулаков
186
+ Терентьев
187
+ Молчанов
188
+ Владимиров
189
+ Артемьев
190
+ Гурьев
191
+ Зиновьев
192
+ Гришин
193
+ Кононов
194
+ Дементьев
195
+ Ситников
196
+ Симонов
197
+ Мишин
198
+ Фадеев
199
+ Комиссаров
200
+ Мамонтов
201
+ Носов
202
+ Гуляев
203
+ Шаров
204
+ Устинов
205
+ Вишняков
206
+ Евсеев
207
+ Лаврентьев
208
+ Брагин
209
+ Константинов
210
+ Корнилов
211
+ Авдеев
212
+ Зыков
213
+ Бирюков
214
+ Шарапов
215
+ Никонов
216
+ Щукин
217
+ Дьячков
218
+ Одинцов
219
+ Сазонов
220
+ Якушев
221
+ Красильников
222
+ Гордеев
223
+ Самойлов
224
+ Князев
225
+ Беспалов
226
+ Уваров
227
+ Шашков
228
+ Бобылёв
229
+ Доронин
230
+ Белозёров
231
+ Рожков
232
+ Самсонов
233
+ Мясников
234
+ Лихачёв
235
+ Буров
236
+ Сысоев
237
+ Фомичёв
238
+ Русаков
239
+ Стрелков
240
+ Гущин
241
+ Тетерин
242
+ Колобов
243
+ Субботин
244
+ Фокин
245
+ Блохин
246
+ Селиверстов
247
+ Пестов
248
+ Кондратьев
249
+ Силин
250
+ Меркушев
251
+ Лыткин
252
+ Туров
@@ -0,0 +1,27 @@
1
+ module Fucker
2
+ module Name
3
+ def make_first_name(lang: :ru, sex: :man)
4
+ _fuck 'first_name_%s_%s' % [lang, sex]
5
+ end
6
+
7
+ def make_last_name(lang: :ru, sex: :man)
8
+ _fuck 'last_name_%s_%s' % [lang, sex]
9
+ end
10
+
11
+ def make_sur_name(lang: :ru, sex: :man)
12
+ _fuck 'sur_name_%s_%s' % [lang, sex]
13
+ end
14
+
15
+ #noinspection RubyNilAnalysis
16
+ def _fuck(filename)
17
+ file = File.expand_path('%s.txt' % filename, File.dirname(__FILE__))
18
+ chosen_line = nil
19
+
20
+ File.foreach(file).each_with_index do |line, number|
21
+ chosen_line = line if rand < 1.0/(number+1)
22
+ end
23
+
24
+ chosen_line.split("\n").join
25
+ end
26
+ end
27
+ end