ykutils 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.8"
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.8
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
@@ -157,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
159
  - !ruby/object:Gem::Version
158
160
  version: '0'
159
161
  requirements: []
160
- rubygems_version: 3.3.7
162
+ rubygems_version: 3.5.11
161
163
  signing_key:
162
164
  specification_version: 4
163
165
  summary: utilty function created by yk.