ykutils 0.1.6 → 0.1.8
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.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/main.yml +2 -0
- data/.gitignore +3 -0
- data/.rubocop_todo.yml +15 -377
- data/Gemfile +7 -8
- data/Gemfile.lock +49 -39
- data/Rakefile +25 -8
- data/SECURITY.md +21 -0
- data/bin/console +0 -0
- data/bin/erubix +1 -1
- data/bin/erubix2 +2 -2
- data/bin/makegrid +1 -1
- data/lib/ykutils/debugutils.rb +52 -50
- data/lib/ykutils/erubyx.rb +5 -7
- data/lib/ykutils/fileoputils.rb +53 -53
- data/lib/ykutils/filepermision.rb +1 -1
- data/lib/ykutils/gridlist.rb +9 -12
- data/lib/ykutils/hasharray.rb +1 -5
- data/lib/ykutils/lines.rb +14 -12
- data/lib/ykutils/lsutils.rb +3 -5
- data/lib/ykutils/nginxconfig.rb +12 -12
- data/lib/ykutils/nginxconfigfiles.rb +10 -12
- data/lib/ykutils/nkfutil.rb +20 -20
- data/lib/ykutils/nkfutil19.rb +16 -16
- data/lib/ykutils/osutil.rb +7 -7
- data/lib/ykutils/pathop.rb +4 -3
- data/lib/ykutils/retcodex.rb +2 -17
- data/lib/ykutils/specfileop.rb +8 -10
- data/lib/ykutils/stext.rb +53 -69
- data/lib/ykutils/stextx.rb +12 -12
- data/lib/ykutils/stringutils.rb +12 -12
- data/lib/ykutils/treemanager.rb +1 -1
- data/lib/ykutils/treemanagera.rb +2 -2
- data/lib/ykutils/version.rb +1 -1
- data/lib/ykutils/yamlop.rb +30 -31
- data/lib/ykutils/yamlxop.rb +0 -5
- data/lib/ykutils.rb +4 -1
- data/ykutils.gemspec +1 -0
- metadata +5 -3
data/lib/ykutils/nginxconfig.rb
CHANGED
@@ -18,23 +18,23 @@ module Ykutils
|
|
18
18
|
def extract(scope)
|
19
19
|
hashx = {}
|
20
20
|
@hash.each do |k, v|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
hashx[k] = Ykutils::Erubyx::erubi_render_with_file(template_pn, scope, value_file_path_array)
|
21
|
+
next unless k !~ /^_/
|
22
|
+
|
23
|
+
# puts k
|
24
|
+
# puts v
|
25
|
+
pn = Pathname.new(v["template"]).cleanpath
|
26
|
+
# Pathname.new(v).cleanpath
|
27
|
+
template_pn = @server_dir_pn + pn
|
28
|
+
# puts(template_pn)
|
29
|
+
value_file_path_array = v["value"].map do |x|
|
30
|
+
@virtual_domain_dir_pn + Pathname.new(x).cleanpath
|
32
31
|
end
|
32
|
+
hashx[k] = Ykutils::Erubyx.erubi_render_with_file(template_pn, scope, value_file_path_array)
|
33
33
|
end
|
34
34
|
template = File.read(@root_template_pn)
|
35
35
|
template_hash = { TEMPLATE: template,
|
36
36
|
OBJ: nil }
|
37
|
-
Ykutils::Erubyx
|
37
|
+
Ykutils::Erubyx.erubi_render(template_hash, scope, hashx)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -1,31 +1,29 @@
|
|
1
1
|
module Ykutils
|
2
|
-
require 'find'
|
3
2
|
class Nginxconfigfiles
|
4
|
-
def get_file_list(
|
3
|
+
def get_file_list(start_dir_pn, reg)
|
5
4
|
@file_list = []
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
6
|
+
start_dir_pn.find { |x|
|
7
|
+
next unless x.to_s =~ reg
|
8
|
+
|
9
|
+
# puts x
|
10
|
+
@file_list << x
|
13
11
|
}
|
14
12
|
@file_list
|
15
13
|
end
|
16
14
|
|
17
15
|
def output(file_list)
|
18
|
-
file_list.map
|
16
|
+
file_list.map do |fname|
|
19
17
|
parent_dir_pn = Pathname.new(fname).cleanpath.parent
|
20
18
|
vdomain = parent_dir_pn.basename
|
21
19
|
output_fname = "#{vdomain}.conf"
|
22
20
|
cli = Nginxconfig.new(fname)
|
23
21
|
scope = nil
|
24
|
-
File.open(output_fname, "w")
|
22
|
+
File.open(output_fname, "w") do |f|
|
25
23
|
x = cli.extract(scope)
|
26
24
|
f.write(x)
|
27
|
-
|
28
|
-
|
25
|
+
end
|
26
|
+
end
|
29
27
|
end
|
30
28
|
end
|
31
29
|
end
|
data/lib/ykutils/nkfutil.rb
CHANGED
@@ -16,19 +16,19 @@ module Ykutils
|
|
16
16
|
end
|
17
17
|
|
18
18
|
class Assoc
|
19
|
-
|
20
|
-
|
19
|
+
@hs = {}
|
20
|
+
@config = nil
|
21
21
|
|
22
22
|
def self.set(key, value)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
@hs[key] = if value
|
24
|
+
Assoc.convert(value)
|
25
|
+
else
|
26
|
+
value
|
27
|
+
end
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.get(key)
|
31
|
-
|
31
|
+
@hs[key]
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.to_nkf_encoding_format(encoding)
|
@@ -41,8 +41,8 @@ module Ykutils
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def self.config(src_encoding, dest_encoding, misc_option = nil)
|
44
|
-
|
45
|
-
|
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
46
|
end
|
47
47
|
|
48
48
|
def self.auto_config_to_inner(str, misc_option = nil)
|
@@ -55,8 +55,8 @@ module Ykutils
|
|
55
55
|
|
56
56
|
inner_encoding = Assoc.to_nkf_encoding_format(Assoc.get_inner_encoding)
|
57
57
|
if inner_encoding != "A"
|
58
|
-
|
59
|
-
|
58
|
+
@config = "-#{inner_encoding.downcase}#{src_encoding.upcase}"
|
59
|
+
@config += " #{misc_option}" unless misc_option.nil?
|
60
60
|
end
|
61
61
|
src_encoding
|
62
62
|
end
|
@@ -64,20 +64,20 @@ module Ykutils
|
|
64
64
|
def self.auto_config_from_inner(dest_enc, misc_option = nil)
|
65
65
|
dest_encoding = Assoc.to_nkf_encoding_format(dest_enc)
|
66
66
|
inner_encoding = Assoc.to_nkf_encoding_format(Assoc.get_inner_encoding)
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
return unless inner_encoding != "A"
|
68
|
+
|
69
|
+
@config = "-#{dest_encoding.downcase}#{inner_encoding.upcase}"
|
70
|
+
@config += " #{misc_option}" unless misc_option.nil?
|
71
71
|
end
|
72
72
|
|
73
73
|
def self.convert(str)
|
74
74
|
nstr = nil
|
75
75
|
unless str.nil?
|
76
|
-
if
|
76
|
+
if @config.nil?
|
77
77
|
nstr = str
|
78
78
|
else
|
79
79
|
begin
|
80
|
-
nstr = NKF.nkf(
|
80
|
+
nstr = NKF.nkf(@config, str)
|
81
81
|
rescue StandardError => e
|
82
82
|
puts e
|
83
83
|
puts "========="
|
@@ -88,8 +88,8 @@ module Ykutils
|
|
88
88
|
nstr
|
89
89
|
end
|
90
90
|
|
91
|
-
def self.
|
92
|
-
|
91
|
+
def self.inner_encoding
|
92
|
+
@inner_encoding = $KCODE == "NONE" ? "ASCII" : $KCODE
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
data/lib/ykutils/nkfutil19.rb
CHANGED
@@ -22,7 +22,7 @@ module Ykutils
|
|
22
22
|
|
23
23
|
begin
|
24
24
|
NAME_TO_ENCODING
|
25
|
-
rescue
|
25
|
+
rescue StandardError
|
26
26
|
NAME_TO_ENCODING = Hash.new("US-ASCII")
|
27
27
|
NAME_TO_ENCODING["UTF8"] = "UTF-8"
|
28
28
|
NAME_TO_ENCODING["ASCII"] = "US-ASCII"
|
@@ -38,19 +38,19 @@ module Ykutils
|
|
38
38
|
end
|
39
39
|
|
40
40
|
class Assoc
|
41
|
-
|
42
|
-
|
41
|
+
@hs = {}
|
42
|
+
@config = nil
|
43
43
|
|
44
44
|
def self.set(key, value)
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
@hs[key] = if value
|
46
|
+
Assoc.convert(value)
|
47
|
+
# else
|
48
|
+
# value
|
49
|
+
end
|
50
50
|
end
|
51
51
|
|
52
52
|
def self.get(key)
|
53
|
-
|
53
|
+
@hs[key]
|
54
54
|
end
|
55
55
|
|
56
56
|
def self.to_nkf_encoding_format(encoding)
|
@@ -58,7 +58,7 @@ module Ykutils
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def self.config(_src_encoding, dest_encoding, _misc_option = nil)
|
61
|
-
|
61
|
+
@config = dest_encoding
|
62
62
|
end
|
63
63
|
|
64
64
|
def self.auto_config_to_inner(str, _misc_option = nil)
|
@@ -70,8 +70,8 @@ module Ykutils
|
|
70
70
|
|
71
71
|
# inner_encoding = Assoc.to_nkf_encoding_format( Assoc.get_inner_encoding )
|
72
72
|
# if inner_encoding != "US-ASCII"
|
73
|
-
#
|
74
|
-
|
73
|
+
# @config = inner_encoding
|
74
|
+
@config = nil
|
75
75
|
# end
|
76
76
|
src_encoding
|
77
77
|
end
|
@@ -80,20 +80,20 @@ module Ykutils
|
|
80
80
|
dest_encoding = Assoc.to_nkf_encoding_format(dest_enc)
|
81
81
|
# inner_encoding = Assoc.to_nkf_encoding_format( Assoc.get_inner_encoding )
|
82
82
|
# if inner_encoding != "US-ASCII"
|
83
|
-
#
|
84
|
-
|
83
|
+
# @config = dest_encoding.downcase
|
84
|
+
@config = dest_encoding
|
85
85
|
# end
|
86
86
|
end
|
87
87
|
|
88
88
|
def self.convert(str)
|
89
89
|
nstr = nil
|
90
90
|
unless str.nil?
|
91
|
-
if
|
91
|
+
if @config.nil?
|
92
92
|
nstr = str
|
93
93
|
else
|
94
94
|
begin
|
95
95
|
# nstr = NKF.nkf( @@config , str )
|
96
|
-
nstr = str.encode(
|
96
|
+
nstr = str.encode(@config)
|
97
97
|
rescue StandardError => e
|
98
98
|
puts e
|
99
99
|
puts "========="
|
data/lib/ykutils/osutil.rb
CHANGED
@@ -2,15 +2,15 @@ require "pathname"
|
|
2
2
|
|
3
3
|
module Ykutils
|
4
4
|
class OSUtil
|
5
|
-
|
5
|
+
@os = nil
|
6
6
|
|
7
7
|
def self.runtime
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
@os ||= if Pathname.pwd.to_s =~ %r{^/cygdrive}
|
9
|
+
:CYGWIN
|
10
|
+
else
|
11
|
+
:ELSE
|
12
|
+
end
|
13
|
+
@os
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/lib/ykutils/pathop.rb
CHANGED
@@ -6,7 +6,7 @@ module Ykutils
|
|
6
6
|
one_path = Pathname.new(fname).expand_path
|
7
7
|
dir_path = one_path.dirname
|
8
8
|
base_path = one_path.basename(".*")
|
9
|
-
append_name = "-2" unless append_name.empty?
|
9
|
+
append_name = "-2" unless append_name.empty? || extname.empty?
|
10
10
|
extname ||= one_path.extname
|
11
11
|
|
12
12
|
[one_path, dir_path.join(base_path.to_s + append_name + extname)]
|
@@ -19,10 +19,11 @@ module Ykutils
|
|
19
19
|
def determine_fname_for_update2(fname)
|
20
20
|
begin
|
21
21
|
ctime = File.ctime(fname)
|
22
|
-
rescue
|
22
|
+
rescue YkutilsError => e
|
23
|
+
puts e
|
23
24
|
end
|
24
25
|
ctime ||= Time.now
|
25
|
-
ary = ctime.to_s.split
|
26
|
+
ary = ctime.to_s.split
|
26
27
|
extname = File.extname(fname)
|
27
28
|
append = ["", ary[0], ary[1].gsub(":", "-")].join("-")
|
28
29
|
get_buddy_path(fname, append, extname)
|
data/lib/ykutils/retcodex.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Ykutils
|
2
2
|
class RetCode
|
3
|
-
attr_reader :val
|
3
|
+
attr_reader :val
|
4
|
+
attr_accessor :bool, :mes, :ret
|
4
5
|
|
5
6
|
def initialize(obj)
|
6
7
|
@val = obj
|
@@ -16,22 +17,6 @@ module Ykutils
|
|
16
17
|
def to_s
|
17
18
|
@bool
|
18
19
|
end
|
19
|
-
|
20
|
-
def set_bool(val)
|
21
|
-
@bool = val
|
22
|
-
end
|
23
|
-
|
24
|
-
def get_bool
|
25
|
-
@bool
|
26
|
-
end
|
27
|
-
|
28
|
-
def set_mes(val)
|
29
|
-
@mes = val
|
30
|
-
end
|
31
|
-
|
32
|
-
def set_ret(val)
|
33
|
-
@ret = val
|
34
|
-
end
|
35
20
|
end
|
36
21
|
|
37
22
|
class RetCode2 < RetCode
|
data/lib/ykutils/specfileop.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# -*- coding utf-8 -*-
|
2
2
|
|
3
|
-
require "pp"
|
4
3
|
require "yaml"
|
5
4
|
require "csv"
|
6
5
|
require "ykutils/treemanagera"
|
@@ -63,7 +62,7 @@ module Ykutils
|
|
63
62
|
|
64
63
|
def parse_yaml_file(fname)
|
65
64
|
begin
|
66
|
-
@data = YAML.
|
65
|
+
@data = YAML.parse_file(fname)
|
67
66
|
rescue StandardError => e
|
68
67
|
pp e
|
69
68
|
pp e.backtrace
|
@@ -82,7 +81,7 @@ module Ykutils
|
|
82
81
|
v.scan(re).flatten.each do |it|
|
83
82
|
if it
|
84
83
|
tm.add(it, k)
|
85
|
-
tm.
|
84
|
+
tm.tag(k, it)
|
86
85
|
else
|
87
86
|
tm.add(nil, k)
|
88
87
|
end
|
@@ -92,10 +91,9 @@ module Ykutils
|
|
92
91
|
tm.tsort.reverse.each do |k|
|
93
92
|
next unless data[k]
|
94
93
|
|
95
|
-
tag = tm.
|
94
|
+
tag = tm.tag(k)
|
96
95
|
next unless tag
|
97
96
|
|
98
|
-
i = 0
|
99
97
|
tag.each do |it|
|
100
98
|
ntag = Regexp.new(separator + it + separator)
|
101
99
|
data[k] = data[k].sub(ntag, data[it]) if data[it]
|
@@ -107,12 +105,12 @@ module Ykutils
|
|
107
105
|
|
108
106
|
ary = v.scan(re).flatten
|
109
107
|
i = 0
|
110
|
-
if ary
|
108
|
+
if ary && !ary.empty?
|
111
109
|
except_ary.each do |it|
|
112
110
|
i += 1 unless ary.index(it)
|
113
111
|
end
|
114
112
|
end
|
115
|
-
if i
|
113
|
+
if i.positive?
|
116
114
|
puts "#{k} fails to exapnd data. value is #{v}"
|
117
115
|
@valid = false
|
118
116
|
end
|
@@ -123,7 +121,7 @@ module Ykutils
|
|
123
121
|
|
124
122
|
def make_data_complement(item_ary, data, common)
|
125
123
|
item_ary.each do |it|
|
126
|
-
data[it] = common[it] unless data[it]
|
124
|
+
data[it] = common[it] unless data[it] && (data[it].strip != "")
|
127
125
|
end
|
128
126
|
end
|
129
127
|
|
@@ -182,9 +180,9 @@ module Ykutils
|
|
182
180
|
|
183
181
|
begin
|
184
182
|
ary0 = File.readlines(fname)
|
185
|
-
|
183
|
+
NKFUTIL.auto_config_to_inner(ary0.join)
|
186
184
|
|
187
|
-
ary = ary0.
|
185
|
+
ary = ary0.compact.collect do |x|
|
188
186
|
if x.nil?
|
189
187
|
""
|
190
188
|
else
|
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
|
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
|
-
|
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
|
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
|
-
|
43
|
+
FileX.open(fname, "w") do |file|
|
44
44
|
@text_ary.each do |l|
|
45
|
-
file.write(l
|
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
|
98
|
-
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
|
103
|
-
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
|
-
|
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(
|
159
|
-
h = item_hash[
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
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(
|
176
|
-
h = item_hash[
|
177
|
-
|
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
|
-
|
184
|
-
|
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
|
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.
|
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.
|
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
|
382
|
+
while (state != :BAD) && (event[0] != :EOF)
|
389
383
|
case state
|
390
|
-
when :NONE
|
391
|
-
|
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
|
data/lib/ykutils/stextx.rb
CHANGED
@@ -6,26 +6,26 @@ module Ykutils
|
|
6
6
|
class StructuredTextForX < StructuredText
|
7
7
|
include DebugUtils
|
8
8
|
|
9
|
-
def initialize(debug
|
9
|
+
def initialize(debug: false)
|
10
10
|
super()
|
11
11
|
|
12
12
|
debug_utils_init
|
13
|
-
|
13
|
+
debug(debug)
|
14
14
|
ends
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def analyze(line_ary, _fname = nil)
|
18
|
+
lines = XLines.new(line_ary)
|
19
|
+
# lines.output_f( fname )
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
analyze_sub(lines)
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
def analyze_sub(lines)
|
25
|
+
puts_current_method
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
end
|
27
|
+
while lines.get_line
|
28
|
+
# p line
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|