ykutils 0.1.7 → 0.1.10

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.
data/lib/ykutils/stext.rb CHANGED
@@ -14,13 +14,13 @@ module Ykutils
14
14
  include DataStructOp
15
15
  include DebugUtils
16
16
 
17
- def initialize(debug = false)
17
+ def initialize(debug: false)
18
18
  @text = nil
19
19
  @fname = nil
20
20
  @text_ary = []
21
21
 
22
22
  debug_utils_init
23
- set_debug(debug)
23
+ debug(debug)
24
24
  end
25
25
 
26
26
  def load_analyze(fname, subfname = nil)
@@ -34,15 +34,15 @@ module Ykutils
34
34
  end
35
35
 
36
36
  def load(fname)
37
- load_plain_text_file(fname).collect { |it| it.chomp }
37
+ load_plain_text_file(fname).collect(&:chomp)
38
38
  end
39
39
 
40
40
  def analyze(line_ary, subfname = nil); end
41
41
 
42
42
  def dump_to_file(fname)
43
- file = FileX.open(fname, "w") do |file|
43
+ FileX.open(fname, "w") do |file|
44
44
  @text_ary.each do |l|
45
- file.write(l + "\n")
45
+ file.write("#{l}\n")
46
46
  end
47
47
  end
48
48
  rescue StandardError => e
@@ -94,13 +94,13 @@ module Ykutils
94
94
  case line["STATUS"]
95
95
  when AccountLines::HOST_ACCOUNT_START, AccountLines::HOST_ACCOUNT, AccountLines::HOST_ACCOUNT_END
96
96
  key, value = line["CONTENT"].split(":") if line["CONTENT"]
97
- key.strip! if key
98
- value.strip! if value
97
+ key&.strip!
98
+ value&.strip!
99
99
  host.analyze(line["STATUS"], line, key, value, @main_host_ary, @main_host_hash)
100
100
  when AccountLines::DOMAIN_ACCOUNT_START, AccountLines::DOMAIN_ACCOUNT, AccountLines::DOMAIN_ACCOUNT_END
101
101
  key, value = line["CONTENT"].split(":") if line["CONTENT"]
102
- key.strip! if key
103
- value.strip! if value
102
+ key&.strip!
103
+ value&.strip!
104
104
  domain.analyze(line["STATUS"], line, key, value, @main_domain_ary, @main_domain_hash)
105
105
  when AccountLines::SEPARATOR
106
106
  key, value = line["CONTENT"].split(":") if line["CONTENT"]
@@ -118,15 +118,13 @@ module Ykutils
118
118
  def sort_by(other)
119
119
  diff_main_host_ary = @main_host_ary - other.main_host_ary
120
120
  diff_main_domain_ary = @main_domain_ary - other.main_domain_ary
121
-
122
- n_main_sep_ary = []
123
121
  n_main_sep_hash = {}
124
122
  n_main_host_ary = []
125
123
  n_main_host_hash = {}
126
124
  n_main_domain_ary = []
127
125
  n_main_domain_hash = {}
128
126
 
129
- if other.main_sep_ary.size > 0
127
+ unless other.main_sep_ary.empty?
130
128
  @main_sep_ary |= other.main_sep_ary
131
129
  @main_sep_hash |= n_main_sep_hash
132
130
  end
@@ -155,33 +153,33 @@ module Ykutils
155
153
  @main_domain_hash = n_main_domain_hash
156
154
  end
157
155
 
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
156
+ def sort_by_sub(itx, item_hash, item_ary, n_hash, n_ary)
157
+ h = item_hash[itx]
158
+ return unless h
159
+
160
+ n_ary << itx
161
+ title = h["TITLE"]
162
+ hash = h["CONTENT"]
163
+ ary = []
164
+ if hash
165
+ item_ary.each do |ai|
166
+ v = hash[ai]
167
+ ary << ai if v
170
168
  end
171
- n_hash[it] = { "TITLE" => title, "META" => ary, "CONTENT" => hash }
172
169
  end
170
+ n_hash[itx] = { "TITLE" => title, "META" => ary, "CONTENT" => hash }
173
171
  end
174
172
 
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"]
173
+ def sort_by_sub_for_array(itx, item_hash, n_hash, n_ary)
174
+ h = item_hash[itx]
175
+ return unless h
182
176
 
183
- n_hash[it] = { "TITLE" => title, "META" => ary, "CONTENT" => hash }
184
- end
177
+ n_ary << itx
178
+ title = h["TITLE"]
179
+ ary = h["META"]
180
+ hash = h["CONTENT"]
181
+
182
+ n_hash[it] = { "TITLE" => title, "META" => ary, "CONTENT" => hash }
185
183
  end
186
184
 
187
185
  def dump(file = nil)
@@ -269,10 +267,6 @@ module Ykutils
269
267
  end
270
268
 
271
269
  class StructuredTextForAccountOneLayerHost < StructuredTextForAccountOneLayer
272
- def initialize
273
- super
274
- end
275
-
276
270
  def analyze(status, line, key, _value, main_ary, main_hash)
277
271
  case status
278
272
  when AccountLines::HOST_ACCOUNT_START
@@ -312,23 +306,23 @@ module Ykutils
312
306
  @item_ary = {}
313
307
  end
314
308
 
315
- def get_event
309
+ def event
316
310
  value = nil
317
311
  line = @line_ary.shift
318
312
 
319
313
  if line
320
314
  content = line.strip
321
- if content.length == 0
315
+ if content.empty?
322
316
  ret = :EMPTY_LINE
323
317
  value = ""
324
318
  elsif content =~ /^-(.*)/
325
319
  title = Regexp.last_match(1)
326
- if title.length > 0
327
- ret = :TITLE_LINE
328
- value = title
329
- else
320
+ if title.empty?
330
321
  ret = :EMPTY_TITLE_LINE
331
322
  value = ""
323
+ else
324
+ ret = :TITLE_LINE
325
+ value = title
332
326
  end
333
327
  else
334
328
  ret = :NON_EMPTY_LINE
@@ -385,34 +379,13 @@ module Ykutils
385
379
 
386
380
  @item_ary = []
387
381
  item = nil
388
- while state != :BAD and event[0] != :EOF
382
+ while (state != :BAD) && (event[0] != :EOF)
389
383
  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
384
+ when :NONE, :ITEM
385
+ procx
410
386
  else
411
387
  case event[0]
412
- when :EMPTY_LINE
413
- when :TITLE_LINE
414
- when :EMPTY_TITLE_LINE
415
- when :NON_EMPTY_LINE
388
+ when :EMPTY_LINE, :TITLE_LINE, :EMPTY_TITLE_LINE, :NON_EMPTY_LINE
416
389
  item.add(event[1])
417
390
  end
418
391
  end
@@ -423,5 +396,16 @@ module Ykutils
423
396
 
424
397
  @item_ary
425
398
  end
399
+
400
+ def procx
401
+ case event[0]
402
+ when :EMPTY_LINE, :TITLE_LINE
403
+ @item_ary << (Item.new(event[1]))
404
+ when :EMPTY_TITLE_LINE
405
+ @item_ary << (Item.new(""))
406
+ when :NON_EMPTY_LINE
407
+ item.add(event[1])
408
+ end
409
+ end
426
410
  end
427
411
  end
@@ -6,26 +6,26 @@ module Ykutils
6
6
  class StructuredTextForX < StructuredText
7
7
  include DebugUtils
8
8
 
9
- def initialize(debug = false)
9
+ def initialize(debug: false)
10
10
  super()
11
11
 
12
12
  debug_utils_init
13
- set_debug(debug)
13
+ debug(debug)
14
14
  ends
15
+ end
15
16
 
16
- def analyze(line_ary, _fname = nil)
17
- lines = XLines.new(line_ary)
18
- # lines.output_f( fname )
17
+ def analyze(line_ary, _fname = nil)
18
+ lines = XLines.new(line_ary)
19
+ # lines.output_f( fname )
19
20
 
20
- analyze_sub(lines)
21
- end
21
+ analyze_sub(lines)
22
+ end
22
23
 
23
- def analyze_sub(lines)
24
- puts_current_method
24
+ def analyze_sub(lines)
25
+ puts_current_method
25
26
 
26
- while (line = lines.get_line)
27
- # p line
28
- end
27
+ while lines.get_line
28
+ # p line
29
29
  end
30
30
  end
31
31
  end
@@ -4,8 +4,8 @@ module Ykutils
4
4
  str || ""
5
5
  end
6
6
 
7
- def get_basename_ext(it)
8
- bn0 = it.basename.to_s
7
+ def get_basename_ext(itx)
8
+ bn0 = itx.basename.to_s
9
9
  if RUBY_VERSION > "1.9"
10
10
  # bn0.encode!( "internal" )
11
11
  bn0.encode! "UTF-8"
@@ -48,7 +48,7 @@ module Ykutils
48
48
  content_ary = []
49
49
 
50
50
  reg_hash = {}
51
- tag_value_hash.each do |k, _v|
51
+ tag_value_hash.each_key do |k|
52
52
  reg_hash[k] = Regexp.new(separator + k + separator)
53
53
  end
54
54
 
@@ -61,17 +61,17 @@ module Ykutils
61
61
  content_ary
62
62
  end
63
63
 
64
- def indent(n)
64
+ def indent(num)
65
65
  n ||= 0
66
66
  @indent_hash ||= {}
67
- @indent_hash[n] ||= " " * n
68
- @indent_hash[n]
67
+ @indent_hash[num] ||= " " * n
68
+ @indent_hash[num]
69
69
  end
70
70
 
71
71
  def print_hier(data, level)
72
72
  case data.class.to_s
73
73
  when "Hash"
74
- data.each do |_k, v|
74
+ data.each_value do |v|
75
75
  # puts "#{indent(level)}#{k}|#{v.class} #{if v.class.to_s == 'String' then v.size else '' end }"
76
76
  # puts "#{indent(level)}#{k}|#{v.class}"
77
77
  print_hier(v, level + 1)
@@ -80,12 +80,12 @@ module Ykutils
80
80
  data.each do |v|
81
81
  print_hier(v, level + 1)
82
82
  end
83
- else
83
+ # else
84
84
  # puts "#{indent(level)}|#{data.class}"
85
85
  end
86
86
  end
87
87
 
88
- def print_hier_2(data, level)
88
+ def print_hier2(data, level)
89
89
  case data.class.to_s
90
90
  when "Hash"
91
91
  data.each do |k, v|
@@ -93,8 +93,8 @@ module Ykutils
93
93
  str = "#{indent(level)}#{k}|#{v.class}"
94
94
  if v.instance_of?(Array)
95
95
  num = v.size
96
- str += ("|" + num.to_s)
97
- str += "###################" if num > 1
96
+ str += "|#{num}"
97
+ "#{str}###################" if num > 1
98
98
  end
99
99
  # puts str
100
100
  print_hier_2(v, level + 1) if k != "group"
@@ -103,7 +103,7 @@ module Ykutils
103
103
  data.each do |v|
104
104
  print_hier_2(v, level + 1)
105
105
  end
106
- else
106
+ # else
107
107
  # puts "#{indent(level)}|#{data.class}"
108
108
  end
109
109
  end
@@ -23,7 +23,7 @@ module Ykytils
23
23
 
24
24
  def tsort_each_child(node, &block)
25
25
  ary = @table[node]
26
- ary.each(&block) if ary
26
+ ary&.each(&block)
27
27
  end
28
28
 
29
29
  def tsort_each_node(&block)
@@ -2,7 +2,7 @@ require "ykutils/treemanager"
2
2
 
3
3
  module Ykutils
4
4
  class TreeManager
5
- def addTag(node_name, tag_name)
5
+ def add_tag(node_name, tag_name)
6
6
  @tag ||= {}
7
7
 
8
8
  if @tag[node_name]
@@ -12,7 +12,7 @@ module Ykutils
12
12
  end
13
13
  end
14
14
 
15
- def getTag(node_name)
15
+ def tag(node_name)
16
16
  ret = nil
17
17
  ret = @tag[node_name] if @tag
18
18
  ret
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ykutils
4
- VERSION = "0.1.7"
4
+ VERSION = "0.1.10"
5
5
  end
@@ -12,7 +12,7 @@ module Ykutils
12
12
  TEST_ID_NO_VALUE = 0
13
13
  TEST_ID_LISTUP_ALL = 1
14
14
 
15
- def initialize(opts = {}, _argv = [], _debug = false)
15
+ def initialize(opts = {}, _argv = [], _debug: false)
16
16
  @fname = nil
17
17
  @check_flag = opts["check"]
18
18
  @ifname = opts["input_file"]
@@ -30,7 +30,7 @@ module Ykutils
30
30
  def exec
31
31
  if @reform_flag
32
32
  reform
33
- elsif @test_id > 0
33
+ elsif @test_id.positive?
34
34
  case @test_id
35
35
  when TEST_ID_LISTUP_ALL
36
36
  test_listup
@@ -104,8 +104,8 @@ module Ykutils
104
104
 
105
105
  def import(fname)
106
106
  ret = false
107
- if File.file?(fname) and File.readable?(fname)
108
- @ptext = load_plain_text_file(fname).collect { |it| it.chomp }
107
+ if File.file?(fname) && File.readable?(fname)
108
+ @ptext = load_plain_text_file(fname).collect(&:chomp)
109
109
  ret = false
110
110
  end
111
111
  ret
@@ -115,10 +115,9 @@ module Ykutils
115
115
  ret = import(fname)
116
116
  if ret
117
117
  @ptext_hash = {}
118
- i = 0
119
118
  @ptext_hash = make_hash(@ptext, 0) do |l, i|
120
- if l !~ /^\s/ and l !~ /^==/
121
- key, vale = l.split(":")
119
+ if l !~ (/^\s/) && l !~ (/^==/)
120
+ key, = l.split(":")
122
121
  [key, { "CONTENT" => l, "INDEX" => i }]
123
122
  end
124
123
  end
@@ -136,14 +135,14 @@ module Ykutils
136
135
  end
137
136
 
138
137
  def listup_domain
139
- @ptext.select { |l| l =~ /^==/ }
138
+ @ptext.grep(/^==/)
140
139
  end
141
140
 
142
141
  def output_yaml(obj, fname)
143
142
  File.open(fname, "w") do |file|
144
143
  YAML.dump(obj, file)
145
144
  end
146
- rescue StandardError => e
145
+ rescue YkutilsError => e
147
146
  pp e
148
147
  pp e.backtrace
149
148
  @valid = false
@@ -165,19 +164,19 @@ module Ykutils
165
164
  File.open(fname, "w") do |file|
166
165
  @yamlstext.dump(file)
167
166
  end
168
- rescue StandardError => e
167
+ rescue YkutilsError => e
169
168
  pp e
170
169
  pp e.backtrace
171
170
  @valid = false
172
171
  end
173
172
 
174
173
  def dump_ptext_to_file(fname)
175
- file = File.open(fname, "w") do |file|
174
+ File.open(fname, "w") do |file|
176
175
  @ptext.each do |l|
177
- file.write(l + "\n")
176
+ file.write("#{l}\n")
178
177
  end
179
178
  end
180
- rescue StandardError => e
179
+ rescue YkutilsdError => e
181
180
  pp e
182
181
  pp e.backtrace
183
182
  @valid = false
@@ -190,25 +189,25 @@ module Ykutils
190
189
 
191
190
  def reform
192
191
  ret = importex(@ifname)
193
- if ret
194
- ary = listup_host.collect do |it|
195
- key, value = it.split(":")
196
- key
197
- end
198
- str = ary.join(" , ")
199
- new_host_list = "=-HOST_LIST: [#{str}]"
200
- ary2 = listup_domain.collect do |it|
201
- key, value = it.split(":")
202
- key
203
- end
204
- str2 = ary2.join(" , ")
205
- new_domain_list = "=-DOMAIN_LIST: [#{str2}]"
206
- pp "==new_host_list"
207
- pp new_host_list
208
- exchange_ptext("=-HOST_LIST", new_host_list)
209
- exchange_ptext("=-DOMAIN_LIST", new_domain_list)
210
- dump_ptext_to_file(@ofname)
192
+ return unless ret
193
+
194
+ ary = listup_host.collect do |it|
195
+ key, = it.split(":")
196
+ key
197
+ end
198
+ str = ary.join(" , ")
199
+ new_host_list = "=-HOST_LIST: [#{str}]"
200
+ ary2 = listup_domain.collect do |it|
201
+ key, = it.split(":")
202
+ key
211
203
  end
204
+ str2 = ary2.join(" , ")
205
+ new_domain_list = "=-DOMAIN_LIST: [#{str2}]"
206
+ pp "==new_host_list"
207
+ pp new_host_list
208
+ exchange_ptext("=-HOST_LIST", new_host_list)
209
+ exchange_ptext("=-DOMAIN_LIST", new_domain_list)
210
+ dump_ptext_to_file(@ofname)
212
211
  end
213
212
 
214
213
  def extract_value(ary)
@@ -8,11 +8,6 @@ module Ykutils
8
8
 
9
9
  include DebugUtils
10
10
 
11
- def initialize(_opt, _args, debug)
12
- debug_utils_init
13
- set_debug(debug)
14
- end
15
-
16
11
  def load(fname)
17
12
  # d_puts "3"
18
13
  # puts_current_method
data/lib/ykutils.rb CHANGED
@@ -26,8 +26,11 @@ require "ykutils/xlines"
26
26
  require "ykutils/yamlop"
27
27
  require "ykutils/yamlxop"
28
28
 
29
- require 'pathname'
29
+ require "pathname"
30
30
  module Ykutils
31
31
  TEST_DATA_DIR = Pathname.new(__dir__).parent + "test_data"
32
32
  # Your code goes here...
33
+
34
+ class YkutilsError < StandardError
35
+ end
33
36
  end
data/ykutils.gemspec CHANGED
@@ -38,6 +38,7 @@ Gem::Specification.new do |spec|
38
38
  spec.add_dependency "tilt"
39
39
  # spec.add_development_dependency "rubocop-rake"
40
40
  # spec.add_development_dependency "rubocop-rspec"
41
+ # spec.add_development_dependency 'yard'
41
42
 
42
43
  # For more information and examples about making a new gem, check out our
43
44
  # guide at: https://bundler.io/guides/creating_gem.html
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ykutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - yasuo kominami
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-30 00:00:00.000000000 Z
11
+ date: 2024-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubi
@@ -59,6 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - ".github/dependabot.yml"
62
63
  - ".github/workflows/main.yml"
63
64
  - ".gitignore"
64
65
  - ".rspec"
@@ -71,6 +72,7 @@ files:
71
72
  - LICENSE.txt
72
73
  - README.md
73
74
  - Rakefile
75
+ - SECURITY.md
74
76
  - bin/console
75
77
  - bin/erubix
76
78
  - bin/erubix2
@@ -90,6 +92,7 @@ files:
90
92
  - lib/ykutils/nginxconfigfiles.rb
91
93
  - lib/ykutils/nkfutil.rb
92
94
  - lib/ykutils/nkfutil19.rb
95
+ - lib/ykutils/nkfutil20.rb
93
96
  - lib/ykutils/osutil.rb
94
97
  - lib/ykutils/pathop.rb
95
98
  - lib/ykutils/retcodex.rb
@@ -157,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
160
  - !ruby/object:Gem::Version
158
161
  version: '0'
159
162
  requirements: []
160
- rubygems_version: 3.3.7
163
+ rubygems_version: 3.5.11
161
164
  signing_key:
162
165
  specification_version: 4
163
166
  summary: utilty function created by yk.