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/nkfutil.rb
CHANGED
@@ -1,147 +1,148 @@
|
|
1
|
-
# -*- coding utf-8 -*-
|
2
|
-
|
3
|
-
require "nkf"
|
4
|
-
|
5
|
-
module Ykutils
|
6
|
-
module NKFUTIL
|
7
|
-
CODE_TO_NAME = Hash.new("ASCII")
|
8
|
-
CODE_TO_NAME[NKF::JIS] = "JIS"
|
9
|
-
CODE_TO_NAME[NKF::EUC] = "EUC"
|
10
|
-
CODE_TO_NAME[NKF::SJIS] = "SJIS"
|
11
|
-
CODE_TO_NAME[NKF::BINARY] = "BINARY"
|
12
|
-
CODE_TO_NAME[NKF::UTF8] = "UTF8" if NKF.const_defined?(:UTF8)
|
13
|
-
|
14
|
-
def self.guess_encoding(str)
|
15
|
-
CODE_TO_NAME[NKF.guess(str)]
|
16
|
-
end
|
17
|
-
|
18
|
-
class Assoc
|
19
|
-
@@hs = {}
|
20
|
-
@@config = nil
|
21
|
-
|
22
|
-
def self.set(key, value)
|
23
|
-
@@hs[key] = if value
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.get(key)
|
31
|
-
@@hs[key]
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.to_nkf_encoding_format(encoding)
|
35
|
-
case encoding
|
36
|
-
when "UTF8"
|
37
|
-
"w"
|
38
|
-
else
|
39
|
-
encoding[0, 1]
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.config(src_encoding, dest_encoding, misc_option = nil)
|
44
|
-
@@config = "-#{dest_encoding.to_s[0, 1].downcase}#{src_encoding.to_s[0, 1].upcase}"
|
45
|
-
@@config += " #{misc_option}" unless misc_option.nil?
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.auto_config_to_inner(str, misc_option = nil)
|
49
|
-
src_encoding =
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
@@config
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
@@config
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
puts
|
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
|
-
end
|
1
|
+
# -*- coding utf-8 -*-
|
2
|
+
|
3
|
+
require "nkf"
|
4
|
+
|
5
|
+
module Ykutils
|
6
|
+
module NKFUTIL
|
7
|
+
CODE_TO_NAME = Hash.new("ASCII")
|
8
|
+
CODE_TO_NAME[NKF::JIS] = "JIS"
|
9
|
+
CODE_TO_NAME[NKF::EUC] = "EUC"
|
10
|
+
CODE_TO_NAME[NKF::SJIS] = "SJIS"
|
11
|
+
CODE_TO_NAME[NKF::BINARY] = "BINARY"
|
12
|
+
CODE_TO_NAME[NKF::UTF8] = "UTF8" if NKF.const_defined?(:UTF8)
|
13
|
+
|
14
|
+
def self.guess_encoding(str)
|
15
|
+
CODE_TO_NAME[NKF.guess(str)]
|
16
|
+
end
|
17
|
+
|
18
|
+
class Assoc
|
19
|
+
@@hs = {}
|
20
|
+
@@config = nil
|
21
|
+
|
22
|
+
def self.set(key, value)
|
23
|
+
@@hs[key] = if value
|
24
|
+
Assoc.convert(value)
|
25
|
+
else
|
26
|
+
value
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get(key)
|
31
|
+
@@hs[key]
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.to_nkf_encoding_format(encoding)
|
35
|
+
case encoding
|
36
|
+
when "UTF8"
|
37
|
+
"w"
|
38
|
+
else
|
39
|
+
encoding[0, 1]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.config(src_encoding, dest_encoding, misc_option = nil)
|
44
|
+
@@config = "-#{dest_encoding.to_s[0, 1].downcase}#{src_encoding.to_s[0, 1].upcase}"
|
45
|
+
@@config += " #{misc_option}" unless misc_option.nil?
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.auto_config_to_inner(str, misc_option = nil)
|
49
|
+
src_encoding =
|
50
|
+
if str
|
51
|
+
Assoc.to_nkf_encoding_format(NKFUTIL.guess_encoding(str))
|
52
|
+
else
|
53
|
+
"A"
|
54
|
+
end
|
55
|
+
|
56
|
+
inner_encoding = Assoc.to_nkf_encoding_format(Assoc.get_inner_encoding)
|
57
|
+
if inner_encoding != "A"
|
58
|
+
@@config = "-#{inner_encoding.downcase}#{src_encoding.upcase}"
|
59
|
+
@@config += " #{misc_option}" unless misc_option.nil?
|
60
|
+
end
|
61
|
+
src_encoding
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.auto_config_from_inner(dest_enc, misc_option = nil)
|
65
|
+
dest_encoding = Assoc.to_nkf_encoding_format(dest_enc)
|
66
|
+
inner_encoding = Assoc.to_nkf_encoding_format(Assoc.get_inner_encoding)
|
67
|
+
if inner_encoding != "A"
|
68
|
+
@@config = "-#{dest_encoding.downcase}#{inner_encoding.upcase}"
|
69
|
+
@@config += " #{misc_option}" unless misc_option.nil?
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.convert(str)
|
74
|
+
nstr = nil
|
75
|
+
unless str.nil?
|
76
|
+
if @@config.nil?
|
77
|
+
nstr = str
|
78
|
+
else
|
79
|
+
begin
|
80
|
+
nstr = NKF.nkf(@@config, str)
|
81
|
+
rescue StandardError => e
|
82
|
+
puts e
|
83
|
+
puts "========="
|
84
|
+
pp caller(0)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
nstr
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.get_inner_encoding
|
92
|
+
@@inner_encoding = $KCODE == "NONE" ? "ASCII" : $KCODE
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.set(key, value)
|
97
|
+
Assoc.set(key, value)
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.get(key)
|
101
|
+
Assoc.get(key)
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.convert(str)
|
105
|
+
if str.nil?
|
106
|
+
""
|
107
|
+
else
|
108
|
+
Assoc.convert(str)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.assoc_equal(target, key)
|
113
|
+
target == key || target == Assoc.get(key)
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.config(src_encoding, dest_encoding, misc_option = nil)
|
117
|
+
Assoc.config(src_encoding, dest_encoding, misc_option)
|
118
|
+
end
|
119
|
+
|
120
|
+
def self.auto_config_to_inner(str, misc_option = nil)
|
121
|
+
Assoc.auto_config_to_inner(str, misc_option)
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.auto_config_from_inner(dest_encoding, misc_option = nil)
|
125
|
+
Assoc.auto_config_to_inner(dest_encoding, misc_option)
|
126
|
+
end
|
127
|
+
|
128
|
+
def puts_sj(line)
|
129
|
+
puts NKF.nkf("-Ws -m0", line)
|
130
|
+
end
|
131
|
+
|
132
|
+
def puts_u(line)
|
133
|
+
puts NKF.nkf("-Sw -m0", line)
|
134
|
+
end
|
135
|
+
|
136
|
+
def nkf_utf8_file(infname, outfname)
|
137
|
+
File.open(outfname) do |outf|
|
138
|
+
File.open(infname) do |file|
|
139
|
+
while (line = file.gets)
|
140
|
+
line.chomp!
|
141
|
+
oline = NKF.nkf("-w -m0", line)
|
142
|
+
outf.printf("%s\n", oline)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
data/lib/ykutils/nkfutil19.rb
CHANGED
@@ -37,18 +37,16 @@ module Ykutils
|
|
37
37
|
CODE_TO_NAME[str.encoding.to_s]
|
38
38
|
end
|
39
39
|
|
40
|
-
def self.config(src_encoding, dest_encoding, misc_option = nil); end
|
41
|
-
|
42
40
|
class Assoc
|
43
41
|
@@hs = {}
|
44
42
|
@@config = nil
|
45
43
|
|
46
44
|
def self.set(key, value)
|
47
45
|
@@hs[key] = if value
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
46
|
+
Assoc.convert(value)
|
47
|
+
else
|
48
|
+
value
|
49
|
+
end
|
52
50
|
end
|
53
51
|
|
54
52
|
def self.get(key)
|
@@ -65,10 +63,10 @@ module Ykutils
|
|
65
63
|
|
66
64
|
def self.auto_config_to_inner(str, _misc_option = nil)
|
67
65
|
src_encoding = if str
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
66
|
+
Assoc.to_nkf_encoding_format(NKFUTIL.guess_encoding(str))
|
67
|
+
else
|
68
|
+
"US-ASCII"
|
69
|
+
end
|
72
70
|
|
73
71
|
# inner_encoding = Assoc.to_nkf_encoding_format( Assoc.get_inner_encoding )
|
74
72
|
# if inner_encoding != "US-ASCII"
|
@@ -156,7 +154,7 @@ module Ykutils
|
|
156
154
|
def nkf_utf8_file(infname, outfname)
|
157
155
|
File.open(outfname) do |outf|
|
158
156
|
File.open(infname) do |file|
|
159
|
-
while line = file.gets
|
157
|
+
while (line = file.gets)
|
160
158
|
line.chomp!
|
161
159
|
# oline = NKF.nkf( "-w -m0" , line )
|
162
160
|
oline = line.encode(NAME_TO_ENCODING["UTF8"])
|
data/lib/ykutils/osutil.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
require "pathname"
|
2
|
-
|
3
|
-
module Ykutils
|
4
|
-
class OSUtil
|
5
|
-
@@os = nil
|
6
|
-
|
7
|
-
def self.runtime
|
8
|
-
@@os ||= if Pathname.pwd.to_s =~ %r{^/cygdrive}
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@@os
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
module Ykutils
|
4
|
+
class OSUtil
|
5
|
+
@@os = nil
|
6
|
+
|
7
|
+
def self.runtime
|
8
|
+
@@os ||= if Pathname.pwd.to_s =~ %r{^/cygdrive}
|
9
|
+
:CYGWIN
|
10
|
+
else
|
11
|
+
:ELSE
|
12
|
+
end
|
13
|
+
@@os
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|