ykutils 0.1.4 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +5 -1
- data/.rubocop.yml +2 -1
- data/.rubocop_todo.yml +181 -85
- data/Gemfile +11 -11
- data/Gemfile.lock +17 -12
- data/bin/erubix +1 -1
- data/bin/makegrid +4 -4
- data/lib/ykutils/erubyx.rb +30 -19
- data/lib/ykutils/fileoputils.rb +2 -2
- data/lib/ykutils/gridlist.rb +49 -49
- data/lib/ykutils/lines.rb +143 -143
- data/lib/ykutils/lsutils.rb +71 -71
- data/lib/ykutils/nginxconfig.rb +40 -41
- data/lib/ykutils/nginxconfigfiles.rb +31 -31
- data/lib/ykutils/nkfutil.rb +148 -147
- data/lib/ykutils/nkfutil19.rb +9 -11
- data/lib/ykutils/osutil.rb +16 -16
- data/lib/ykutils/retcodex.rb +1 -3
- data/lib/ykutils/stext.rb +427 -425
- data/lib/ykutils/stextx.rb +32 -32
- data/lib/ykutils/stringutils.rb +111 -111
- data/lib/ykutils/treemanager.rb +33 -33
- data/lib/ykutils/treemanagera.rb +21 -21
- data/lib/ykutils/version.rb +1 -1
- data/lib/ykutils/xlines.rb +8 -8
- data/lib/ykutils/yamlop.rb +227 -227
- data/lib/ykutils/yamlxop.rb +35 -35
- data/test_data/4servers.erb +7 -7
- data/test_data/a.bat +5 -5
- data/test_data/a_ncn.bat +12 -12
- data/test_data/v103-3-189-127/a.northern-cross.net/base.yml +28 -28
- data/test_data/v103-3-189-127/a.northern-cross.net/value_host.yml +1 -1
- data/test_data/v103-3-189-127/b.northern-cross.net/base.yml +28 -28
- data/test_data/v103-3-189-127/b.northern-cross.net/value_host.yml +1 -1
- data/test_data/v103-3-189-127/c.northern-cross.net/base.yml +28 -28
- data/test_data/v103-3-189-127/c.northern-cross.net/value_host.yml +1 -1
- data/test_data/v103-3-189-127/d.northern-cross.info/base.yml +28 -28
- data/test_data/v103-3-189-127/d.northern-cross.info/value_host.yml +1 -1
- data/test_data/v103-3-189-127/d.northern-cross.net/base.yml +28 -28
- data/test_data/v103-3-189-127/d.northern-cross.net/value_host.yml +1 -1
- data/test_data/v103-3-189-127/e.northern-cross.info/base.yml +28 -28
- data/test_data/v103-3-189-127/e.northern-cross.info/value_host.yml +1 -1
- data/test_data/v103-3-189-127/e.northern-cross.net/base.yml +28 -28
- data/test_data/v103-3-189-127/e.northern-cross.net/value_host.yml +1 -1
- data/test_data/v103-3-189-127/f.northern-cross.info/base.yml +28 -28
- data/test_data/v103-3-189-127/f.northern-cross.info/value_host.yml +1 -1
- data/test_data/v103-3-189-127/f.northern-cross.net/base.yml +28 -28
- data/test_data/v103-3-189-127/f.northern-cross.net/value_host.yml +1 -1
- data/test_data/v103-3-189-127/t_server_1.erb +7 -7
- data/test_data/v103-3-189-127/template.erb +21 -21
- data/test_data/v103-3-189-127/template_ssl.erb +22 -22
- data/test_data/v103-3-189-127/template_ssl_www.erb +12 -12
- data/test_data/v103-3-189-127/template_www.erb +24 -24
- data/test_data/v103-3-189-127/value.yml +3 -3
- data/test_data/v103-3-189-127/value_ssl.yml +5 -5
- data/ykutils.gemspec +45 -43
- metadata +8 -9
- data/_config.yml +0 -1
data/lib/ykutils/stext.rb
CHANGED
@@ -1,425 +1,427 @@
|
|
1
|
-
# -*- coding utf-8 -*-
|
2
|
-
|
3
|
-
require "ykutils/debugutils"
|
4
|
-
require "ykutils/lines"
|
5
|
-
require "ykutils/specfileop"
|
6
|
-
require "ykutils/datastructop"
|
7
|
-
require "filex"
|
8
|
-
|
9
|
-
module Ykutils
|
10
|
-
class StructuredText
|
11
|
-
attr_reader :main_ary, :main_hash, :item_ary
|
12
|
-
|
13
|
-
include SpecFileOp
|
14
|
-
include DataStructOp
|
15
|
-
include DebugUtils
|
16
|
-
|
17
|
-
def initialize(debug = false)
|
18
|
-
@text = nil
|
19
|
-
@fname = nil
|
20
|
-
@text_ary = []
|
21
|
-
|
22
|
-
debug_utils_init
|
23
|
-
set_debug(debug)
|
24
|
-
end
|
25
|
-
|
26
|
-
def load_analyze(fname, subfname = nil)
|
27
|
-
# puts_current_method
|
28
|
-
# puts "-0 fname=#{fname}"
|
29
|
-
|
30
|
-
@fname = fname
|
31
|
-
@text_ary = load(fname)
|
32
|
-
# @text_ary.each do |x| puts x end
|
33
|
-
analyze(@text_ary, subfname)
|
34
|
-
end
|
35
|
-
|
36
|
-
def load(fname)
|
37
|
-
load_plain_text_file(fname).collect { |it| it.chomp }
|
38
|
-
end
|
39
|
-
|
40
|
-
def analyze(line_ary, subfname = nil); end
|
41
|
-
|
42
|
-
def dump_to_file(fname)
|
43
|
-
file = FileX.open(fname, "w") do |file|
|
44
|
-
@text_ary.each do |l|
|
45
|
-
file.write(l + "\n")
|
46
|
-
end
|
47
|
-
end
|
48
|
-
rescue StandardError => e
|
49
|
-
pp e
|
50
|
-
pp e.backtrace
|
51
|
-
@valid = false
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
class StructuredTextForFtpOp < StructuredText
|
56
|
-
def analyze(line_ary, fname = nil)
|
57
|
-
lines = FtpOpLines.new(line_ary)
|
58
|
-
lines.output_f(fname)
|
59
|
-
|
60
|
-
analyze_sub(lines)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
class StructuredTextForAccount < StructuredText
|
65
|
-
attr_reader :main_host_ary, :main_host_hash, :main_domain_ary, :main_domain_hash, :main_sep_ary,
|
66
|
-
:main_sep_hash, :main_host_item_ary
|
67
|
-
|
68
|
-
def initialize
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
@
|
73
|
-
|
74
|
-
|
75
|
-
@
|
76
|
-
|
77
|
-
|
78
|
-
@
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
lines.
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
key.
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
key.
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
@
|
109
|
-
|
110
|
-
|
111
|
-
puts(
|
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
|
-
dump_ary
|
189
|
-
dump_ary += dump_sub(@
|
190
|
-
dump_ary +=
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
file.write(
|
198
|
-
|
199
|
-
|
200
|
-
pp e
|
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
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
@
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
@title = ""
|
265
|
-
@
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
@
|
280
|
-
|
281
|
-
|
282
|
-
@
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
@
|
289
|
-
@
|
290
|
-
@
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
@
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
@next_state
|
346
|
-
@next_state[:NONE]
|
347
|
-
@next_state[:NONE][:
|
348
|
-
@next_state[:NONE][:
|
349
|
-
@next_state[:
|
350
|
-
@next_state[:
|
351
|
-
@next_state[:ITEM]
|
352
|
-
@next_state[:ITEM][:
|
353
|
-
@next_state[:ITEM][:
|
354
|
-
@next_state[:
|
355
|
-
@next_state[:
|
356
|
-
@next_state[:END]
|
357
|
-
@next_state[:END][:
|
358
|
-
@next_state[:END][:
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
# :
|
375
|
-
# :
|
376
|
-
|
377
|
-
# :
|
378
|
-
|
379
|
-
# :
|
380
|
-
# :
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
when :
|
394
|
-
@item_ary << (item = Item.new(
|
395
|
-
when :
|
396
|
-
item.
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
when :
|
404
|
-
@item_ary << (item = Item.new(
|
405
|
-
when :
|
406
|
-
item.
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
when :
|
413
|
-
when :
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
end
|
1
|
+
# -*- coding utf-8 -*-
|
2
|
+
|
3
|
+
require "ykutils/debugutils"
|
4
|
+
require "ykutils/lines"
|
5
|
+
require "ykutils/specfileop"
|
6
|
+
require "ykutils/datastructop"
|
7
|
+
require "filex"
|
8
|
+
|
9
|
+
module Ykutils
|
10
|
+
class StructuredText
|
11
|
+
attr_reader :main_ary, :main_hash, :item_ary
|
12
|
+
|
13
|
+
include SpecFileOp
|
14
|
+
include DataStructOp
|
15
|
+
include DebugUtils
|
16
|
+
|
17
|
+
def initialize(debug = false)
|
18
|
+
@text = nil
|
19
|
+
@fname = nil
|
20
|
+
@text_ary = []
|
21
|
+
|
22
|
+
debug_utils_init
|
23
|
+
set_debug(debug)
|
24
|
+
end
|
25
|
+
|
26
|
+
def load_analyze(fname, subfname = nil)
|
27
|
+
# puts_current_method
|
28
|
+
# puts "-0 fname=#{fname}"
|
29
|
+
|
30
|
+
@fname = fname
|
31
|
+
@text_ary = load(fname)
|
32
|
+
# @text_ary.each do |x| puts x end
|
33
|
+
analyze(@text_ary, subfname)
|
34
|
+
end
|
35
|
+
|
36
|
+
def load(fname)
|
37
|
+
load_plain_text_file(fname).collect { |it| it.chomp }
|
38
|
+
end
|
39
|
+
|
40
|
+
def analyze(line_ary, subfname = nil); end
|
41
|
+
|
42
|
+
def dump_to_file(fname)
|
43
|
+
file = FileX.open(fname, "w") do |file|
|
44
|
+
@text_ary.each do |l|
|
45
|
+
file.write(l + "\n")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
rescue StandardError => e
|
49
|
+
pp e
|
50
|
+
pp e.backtrace
|
51
|
+
@valid = false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class StructuredTextForFtpOp < StructuredText
|
56
|
+
def analyze(line_ary, fname = nil)
|
57
|
+
lines = FtpOpLines.new(line_ary)
|
58
|
+
lines.output_f(fname)
|
59
|
+
|
60
|
+
analyze_sub(lines)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class StructuredTextForAccount < StructuredText
|
65
|
+
attr_reader :main_host_ary, :main_host_hash, :main_domain_ary, :main_domain_hash, :main_sep_ary,
|
66
|
+
:main_sep_hash, :main_host_item_ary
|
67
|
+
|
68
|
+
def initialize
|
69
|
+
super()
|
70
|
+
@main_host_item_ary = []
|
71
|
+
|
72
|
+
@main_sep_ary = []
|
73
|
+
@main_sep_hash = {}
|
74
|
+
|
75
|
+
@main_host_ary = []
|
76
|
+
@main_host_hash = {}
|
77
|
+
|
78
|
+
@main_domain_ary = []
|
79
|
+
@main_domain_hash = {}
|
80
|
+
end
|
81
|
+
|
82
|
+
def analyze(line_ary, fname = nil)
|
83
|
+
lines = AccountLines.new(line_ary)
|
84
|
+
lines.output_f(fname)
|
85
|
+
|
86
|
+
analyze_sub(lines)
|
87
|
+
end
|
88
|
+
|
89
|
+
def analyze_sub(lines)
|
90
|
+
host = StructuredTextForAccountOneLayerHost.new
|
91
|
+
domain = StructuredTextForAccountOneLayerDomain.new
|
92
|
+
|
93
|
+
while (line = lines.get_line)
|
94
|
+
case line["STATUS"]
|
95
|
+
when AccountLines::HOST_ACCOUNT_START, AccountLines::HOST_ACCOUNT, AccountLines::HOST_ACCOUNT_END
|
96
|
+
key, value = line["CONTENT"].split(":") if line["CONTENT"]
|
97
|
+
key.strip! if key
|
98
|
+
value.strip! if value
|
99
|
+
host.analyze(line["STATUS"], line, key, value, @main_host_ary, @main_host_hash)
|
100
|
+
when AccountLines::DOMAIN_ACCOUNT_START, AccountLines::DOMAIN_ACCOUNT, AccountLines::DOMAIN_ACCOUNT_END
|
101
|
+
key, value = line["CONTENT"].split(":") if line["CONTENT"]
|
102
|
+
key.strip! if key
|
103
|
+
value.strip! if value
|
104
|
+
domain.analyze(line["STATUS"], line, key, value, @main_domain_ary, @main_domain_hash)
|
105
|
+
when AccountLines::SEPARATOR
|
106
|
+
key, value = line["CONTENT"].split(":") if line["CONTENT"]
|
107
|
+
|
108
|
+
@main_sep_ary << key
|
109
|
+
@main_sep_hash[key] = { "TITLE" => key }
|
110
|
+
else
|
111
|
+
puts("Error")
|
112
|
+
puts(line["CONTENT"])
|
113
|
+
end
|
114
|
+
end
|
115
|
+
@main_host_item_ary |= host.item_ary
|
116
|
+
end
|
117
|
+
|
118
|
+
def sort_by(other)
|
119
|
+
diff_main_host_ary = @main_host_ary - other.main_host_ary
|
120
|
+
diff_main_domain_ary = @main_domain_ary - other.main_domain_ary
|
121
|
+
|
122
|
+
n_main_sep_ary = []
|
123
|
+
n_main_sep_hash = {}
|
124
|
+
n_main_host_ary = []
|
125
|
+
n_main_host_hash = {}
|
126
|
+
n_main_domain_ary = []
|
127
|
+
n_main_domain_hash = {}
|
128
|
+
|
129
|
+
if other.main_sep_ary.size > 0
|
130
|
+
@main_sep_ary |= other.main_sep_ary
|
131
|
+
@main_sep_hash |= n_main_sep_hash
|
132
|
+
end
|
133
|
+
|
134
|
+
main_host_item_ary = other.main_host_item_ary | @main_host_item_ary
|
135
|
+
|
136
|
+
other.main_host_ary.each do |it|
|
137
|
+
sort_by_sub(it, @main_host_hash, main_host_item_ary, n_main_host_hash, n_main_host_ary)
|
138
|
+
end
|
139
|
+
|
140
|
+
diff_main_host_ary.each do |it|
|
141
|
+
sort_by_sub(it, @main_host_hash, main_host_item_ary, n_main_host_hash, n_main_host_ary)
|
142
|
+
end
|
143
|
+
|
144
|
+
other.main_domain_ary.each do |it|
|
145
|
+
sort_by_sub_for_array(it, @main_domain_hash, n_main_domain_hash, n_main_domain_ary)
|
146
|
+
end
|
147
|
+
|
148
|
+
diff_main_domain_ary.each do |it|
|
149
|
+
sort_by_sub_for_array(it, @main_domain_hash, n_main_domain_hash, n_main_domain_ary)
|
150
|
+
end
|
151
|
+
|
152
|
+
@main_host_ary = n_main_host_ary
|
153
|
+
@main_host_hash = n_main_host_hash
|
154
|
+
@main_domain_ary = n_main_domain_ary
|
155
|
+
@main_domain_hash = n_main_domain_hash
|
156
|
+
end
|
157
|
+
|
158
|
+
def sort_by_sub(it, item_hash, item_ary, n_hash, n_ary)
|
159
|
+
h = item_hash[it]
|
160
|
+
if h
|
161
|
+
n_ary << it
|
162
|
+
title = h["TITLE"]
|
163
|
+
hash = h["CONTENT"]
|
164
|
+
ary = []
|
165
|
+
if hash
|
166
|
+
item_ary.each do |ai|
|
167
|
+
v = hash[ai]
|
168
|
+
ary << ai if v
|
169
|
+
end
|
170
|
+
end
|
171
|
+
n_hash[it] = { "TITLE" => title, "META" => ary, "CONTENT" => hash }
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def sort_by_sub_for_array(it, item_hash, n_hash, n_ary)
|
176
|
+
h = item_hash[it]
|
177
|
+
if h
|
178
|
+
n_ary << it
|
179
|
+
title = h["TITLE"]
|
180
|
+
ary = h["META"]
|
181
|
+
hash = h["CONTENT"]
|
182
|
+
|
183
|
+
n_hash[it] = { "TITLE" => title, "META" => ary, "CONTENT" => hash }
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def dump(file = nil)
|
188
|
+
dump_ary = []
|
189
|
+
dump_ary += dump_sub(@main_sep_ary, @main_sep_hash)
|
190
|
+
dump_ary += dump_sub(@main_host_ary, @main_host_hash)
|
191
|
+
dump_ary += dump_sub_for_array(@main_domain_ary, @main_domain_hash)
|
192
|
+
|
193
|
+
str = dump_ary.join("\n")
|
194
|
+
|
195
|
+
if file
|
196
|
+
begin
|
197
|
+
file.write(str)
|
198
|
+
file.write("\n")
|
199
|
+
rescue StandardError => e
|
200
|
+
pp e
|
201
|
+
pp e.backtrace
|
202
|
+
@valid = false
|
203
|
+
end
|
204
|
+
end
|
205
|
+
str
|
206
|
+
end
|
207
|
+
|
208
|
+
def dump_sub(ary, hash)
|
209
|
+
dump_ary = []
|
210
|
+
ary.each do |it|
|
211
|
+
h = hash[it]
|
212
|
+
next unless h
|
213
|
+
|
214
|
+
item_ary = h["META"]
|
215
|
+
title = h["TITLE"]
|
216
|
+
item_hash = h["CONTENT"]
|
217
|
+
dump_ary << title
|
218
|
+
|
219
|
+
next unless item_ary
|
220
|
+
|
221
|
+
item_ary.each do |subit|
|
222
|
+
dump_ary << item_hash[subit] if item_hash[subit]
|
223
|
+
end
|
224
|
+
end
|
225
|
+
dump_ary
|
226
|
+
end
|
227
|
+
|
228
|
+
def dump_sub_for_array(ary, hash)
|
229
|
+
dump_ary = []
|
230
|
+
ary.each do |it|
|
231
|
+
dump_ary += hash[it]["CONTENT"]
|
232
|
+
end
|
233
|
+
dump_ary
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
class StructuredTextForAccountOneLayer
|
238
|
+
attr_accessor :item_ary
|
239
|
+
|
240
|
+
def initialize
|
241
|
+
@item_ary = []
|
242
|
+
@ary = []
|
243
|
+
@hash = {}
|
244
|
+
@title = ""
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
class StructuredTextForAccountOneLayerDomain < StructuredTextForAccountOneLayer
|
249
|
+
def initialize
|
250
|
+
super
|
251
|
+
@line_ary = []
|
252
|
+
end
|
253
|
+
|
254
|
+
def analyze(status, line, key, _value, main_line_ary, main_line_hash)
|
255
|
+
case status
|
256
|
+
when AccountLines::DOMAIN_ACCOUNT_START
|
257
|
+
key.sub!(/^==/, "")
|
258
|
+
@title = line["CONTENT"]
|
259
|
+
@line_ary << line["CONTENT"]
|
260
|
+
when AccountLines::DOMAIN_ACCOUNT
|
261
|
+
@line_ary << line["CONTENT"]
|
262
|
+
when AccountLines::DOMAIN_ACCOUNT_END
|
263
|
+
main_line_ary << @title
|
264
|
+
main_line_hash[@title] = { "TITLE" => @title, "CONTENT" => @line_ary }
|
265
|
+
@title = ""
|
266
|
+
@line_ary = []
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
class StructuredTextForAccountOneLayerHost < StructuredTextForAccountOneLayer
|
272
|
+
def initialize
|
273
|
+
super
|
274
|
+
end
|
275
|
+
|
276
|
+
def analyze(status, line, key, _value, main_ary, main_hash)
|
277
|
+
case status
|
278
|
+
when AccountLines::HOST_ACCOUNT_START
|
279
|
+
@hash[key] = line["CONTENT"]
|
280
|
+
@title = line["CONTENT"]
|
281
|
+
when AccountLines::HOST_ACCOUNT
|
282
|
+
@ary << key
|
283
|
+
@hash[key] = line["CONTENT"]
|
284
|
+
when AccountLines::HOST_ACCOUNT_END
|
285
|
+
main_ary << @title
|
286
|
+
main_hash[@title] = { "TITLE" => @title, "CONTENT" => @hash, "META" => @ary }
|
287
|
+
|
288
|
+
@item_ary |= @ary
|
289
|
+
@ary = []
|
290
|
+
@hash = {}
|
291
|
+
@title = ""
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
class StructuredTextForSimple < StructuredText
|
297
|
+
class Item
|
298
|
+
attr_reader :name, :contents
|
299
|
+
|
300
|
+
def initialize(name)
|
301
|
+
@name = name
|
302
|
+
@contents = []
|
303
|
+
end
|
304
|
+
|
305
|
+
def add(content)
|
306
|
+
@contents << content
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
def initialize
|
311
|
+
super()
|
312
|
+
@item_ary = {}
|
313
|
+
end
|
314
|
+
|
315
|
+
def get_event
|
316
|
+
value = nil
|
317
|
+
line = @line_ary.shift
|
318
|
+
|
319
|
+
if line
|
320
|
+
content = line.strip
|
321
|
+
if content.length == 0
|
322
|
+
ret = :EMPTY_LINE
|
323
|
+
value = ""
|
324
|
+
elsif content =~ /^-(.*)/
|
325
|
+
title = Regexp.last_match(1)
|
326
|
+
if title.length > 0
|
327
|
+
ret = :TITLE_LINE
|
328
|
+
value = title
|
329
|
+
else
|
330
|
+
ret = :EMPTY_TITLE_LINE
|
331
|
+
value = ""
|
332
|
+
end
|
333
|
+
else
|
334
|
+
ret = :NON_EMPTY_LINE
|
335
|
+
value = content
|
336
|
+
end
|
337
|
+
else
|
338
|
+
ret = :EOF
|
339
|
+
end
|
340
|
+
|
341
|
+
[ret, value]
|
342
|
+
end
|
343
|
+
|
344
|
+
def make_next_state_table
|
345
|
+
@next_state = {}
|
346
|
+
@next_state[:NONE] = {}
|
347
|
+
@next_state[:NONE][:EMPTY_LINE] = :NONE
|
348
|
+
@next_state[:NONE][:TITLE_LINE] = :ITEM
|
349
|
+
@next_state[:NONE][:EMPTY_TITLE_LINE] = :END
|
350
|
+
@next_state[:NONE][:NON_EMPTY_LINE] = :BAD
|
351
|
+
@next_state[:ITEM] = {}
|
352
|
+
@next_state[:ITEM][:EMPTY_LINE] = :ITEM
|
353
|
+
@next_state[:ITEM][:TITLE_LINE] = :ITEM
|
354
|
+
@next_state[:ITEM][:EMPTY_TITLE_LINE] = :END
|
355
|
+
@next_state[:ITEM][:NON_EMPTY_LINE] = :ITEM
|
356
|
+
@next_state[:END] = {}
|
357
|
+
@next_state[:END][:EMPTY_LINE] = :END
|
358
|
+
@next_state[:END][:TITLE_LINE] = :BAD
|
359
|
+
@next_state[:END][:EMPTY_TITLE_LINE] = :BAD
|
360
|
+
@next_state[:END][:NON_EMPTY_LINE] = :END
|
361
|
+
end
|
362
|
+
|
363
|
+
def get_next_state(state, event)
|
364
|
+
if state == :BAD
|
365
|
+
:BAD
|
366
|
+
else
|
367
|
+
@next_state[state][event]
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
def analyze(line_ary, _subfname = nil)
|
372
|
+
@line_ary = line_ary
|
373
|
+
make_next_state_table
|
374
|
+
# :NONE
|
375
|
+
# :ITEM
|
376
|
+
# :END
|
377
|
+
# :BAD
|
378
|
+
|
379
|
+
# :EMPTY_LINE
|
380
|
+
# :TITLE_LINE
|
381
|
+
# :EMPTY_TITLE_LINE
|
382
|
+
# :NON_EMPTY_LINE
|
383
|
+
state = :NONE
|
384
|
+
event = get_event
|
385
|
+
|
386
|
+
@item_ary = []
|
387
|
+
item = nil
|
388
|
+
while state != :BAD and event[0] != :EOF
|
389
|
+
case state
|
390
|
+
when :NONE
|
391
|
+
case event[0]
|
392
|
+
when :EMPTY_LINE
|
393
|
+
when :TITLE_LINE
|
394
|
+
@item_ary << (item = Item.new(event[1]))
|
395
|
+
when :EMPTY_TITLE_LINE
|
396
|
+
@item_ary << (item = Item.new(""))
|
397
|
+
when :NON_EMPTY_LINE
|
398
|
+
item.add(event[1])
|
399
|
+
end
|
400
|
+
when :ITEM
|
401
|
+
case event[0]
|
402
|
+
when :EMPTY_LINE
|
403
|
+
when :TITLE_LINE
|
404
|
+
@item_ary << (item = Item.new(event[1]))
|
405
|
+
when :EMPTY_TITLE_LINE
|
406
|
+
@item_ary << (item = Item.new(""))
|
407
|
+
when :NON_EMPTY_LINE
|
408
|
+
item.add(event[1])
|
409
|
+
end
|
410
|
+
else
|
411
|
+
case event[0]
|
412
|
+
when :EMPTY_LINE
|
413
|
+
when :TITLE_LINE
|
414
|
+
when :EMPTY_TITLE_LINE
|
415
|
+
when :NON_EMPTY_LINE
|
416
|
+
item.add(event[1])
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
state = get_next_state(state, event[0])
|
421
|
+
event = get_event
|
422
|
+
end
|
423
|
+
|
424
|
+
@item_ary
|
425
|
+
end
|
426
|
+
end
|
427
|
+
end
|