ykutils 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,6 @@
1
1
  module Ykutils
2
-
3
2
  class RetCode
4
- attr_reader :val , :mes, :ret , :bool
3
+ attr_reader :val, :mes, :ret, :bool
5
4
 
6
5
  def initialize(obj)
7
6
  @val = obj
@@ -18,7 +17,7 @@ module Ykutils
18
17
  @bool
19
18
  end
20
19
 
21
- def set_bool( val )
20
+ def set_bool(val)
22
21
  @bool = val
23
22
  end
24
23
 
@@ -26,25 +25,24 @@ module Ykutils
26
25
  @bool
27
26
  end
28
27
 
29
- def set_mes( val )
28
+ def set_mes(val)
30
29
  @mes = val
31
30
  end
32
31
 
33
- def set_ret( val )
32
+ def set_ret(val)
34
33
  @ret = val
35
34
  end
36
35
  end
37
36
 
38
37
  class RetCode2 < RetCode
39
- attr_reader :val
40
- attr_accessor :mes, :ret , :bool
41
-
42
- def initialize( ret , bool, mes )
43
- @val = { "ret" => ret , "bool" => bool, "mes" => mes }
38
+ attr_reader :val
39
+ attr_accessor :mes, :ret, :bool
40
+
41
+ def initialize(ret, bool, mes)
42
+ @val = { "ret" => ret, "bool" => bool, "mes" => mes }
44
43
  @ret = ret
45
44
  @bool = bool
46
45
  @mes = mes
47
46
  end
48
47
  end
49
-
50
48
  end
@@ -1,18 +1,17 @@
1
1
  # -*- coding utf-8 -*-
2
2
 
3
- require 'pp'
4
- require 'yaml'
5
- require 'csv'
6
- require 'ykutils/treemanagera'
3
+ require "pp"
4
+ require "yaml"
5
+ require "csv"
6
+ require "ykutils/treemanagera"
7
7
  if RUBY_VERSION >= "1.8.7"
8
- require 'ykutils/nkfutil19'
8
+ require "ykutils/nkfutil19"
9
9
  else
10
- require 'ykutils/nkfutil'
10
+ require "ykutils/nkfutil"
11
11
  end
12
- require 'ykutils/debugutils'
12
+ require "ykutils/debugutils"
13
13
 
14
14
  module Ykutils
15
-
16
15
  module SpecFileOp
17
16
  include DebugUtils
18
17
  include NKFUTIL
@@ -21,102 +20,96 @@ module Ykutils
21
20
  @valid
22
21
  end
23
22
 
24
- def open_for_write( fname )
23
+ def open_for_write(fname)
25
24
  begin
26
- fileobj = File.open( fname , "w")
27
- rescue => ex
28
- pp ex
29
- pp ex.backtrace
25
+ fileobj = File.open(fname, "w")
26
+ rescue StandardError => e
27
+ pp e
28
+ pp e.backtrace
30
29
  @valid = false
31
30
  end
32
31
  fileobj
33
32
  end
34
33
 
35
- def dump_yaml_fileobj( obj , fileobj )
36
- begin
37
- YAML.dump( obj , fileobj)
38
- rescue => ex
39
- pp ex
40
- pp ex.backtrace
41
- @valid = false
42
- end
34
+ def dump_yaml_fileobj(obj, fileobj)
35
+ YAML.dump(obj, fileobj)
36
+ rescue StandardError => e
37
+ pp e
38
+ pp e.backtrace
39
+ @valid = false
43
40
  end
44
41
 
45
- def save_yaml_file( obj , fname )
46
- begin
47
- File.open( fname , "w"){ |fileobj|
48
- YAML.dump( obj , fileobj )
49
- }
50
- rescue => ex
51
- pp ex
52
- pp ex.backtrace
53
- @valid = false
42
+ def save_yaml_file(obj, fname)
43
+ File.open(fname, "w") do |fileobj|
44
+ YAML.dump(obj, fileobj)
54
45
  end
46
+ rescue StandardError => e
47
+ pp e
48
+ pp e.backtrace
49
+ @valid = false
55
50
  end
56
51
 
57
- def load_yaml_file( fname )
52
+ def load_yaml_file(fname)
58
53
  @data = nil
59
54
  begin
60
55
  @data = YAML.load_file(fname)
61
- rescue => ex
62
- pp ex
63
- pp ex.backtrace
56
+ rescue StandardError => e
57
+ pp e
58
+ pp e.backtrace
64
59
  @valid = false
65
60
  end
66
61
  @data
67
62
  end
68
63
 
69
- def parse_yaml_file( fname )
64
+ def parse_yaml_file(fname)
70
65
  begin
71
- @data = YAML.parse( File.read(fname) )
72
- rescue => ex
73
- pp ex
74
- pp ex.backtrace
66
+ @data = YAML.parse(File.read(fname))
67
+ rescue StandardError => e
68
+ pp e
69
+ pp e.backtrace
75
70
  @valid = false
76
71
  end
77
72
  @data
78
73
  end
79
74
 
80
- def expand_data( data , separator , except_ary = [] )
75
+ def expand_data(data, separator, except_ary = [])
81
76
  tm = TreeManager.new
82
- re = Regexp.new( separator + "([^#{separator[0,1]}]+)" + separator )
83
-
84
- data.each do |k,v|
77
+ re = Regexp.new(separator + "([^#{separator[0, 1]}]+)" + separator)
78
+
79
+ data.each do |k, v|
85
80
  next unless v
81
+
86
82
  v.scan(re).flatten.each do |it|
87
83
  if it
88
- tm.add( it , k )
89
- tm.addTag( k , it )
84
+ tm.add(it, k)
85
+ tm.addTag(k, it)
90
86
  else
91
- tm.add( nil , k )
87
+ tm.add(nil, k)
92
88
  end
93
89
  end
94
- end
90
+ end
95
91
 
96
92
  tm.tsort.reverse.each do |k|
97
93
  next unless data[k]
98
94
 
99
95
  tag = tm.getTag(k)
100
- if tag
101
- i=0
102
- tag.each do |it|
103
- ntag = Regexp.new( separator + it + separator )
104
- if data[it]
105
- data[k] = data[k].sub( ntag , data[it] )
106
- end
107
- end
96
+ next unless tag
97
+
98
+ i = 0
99
+ tag.each do |it|
100
+ ntag = Regexp.new(separator + it + separator)
101
+ data[k] = data[k].sub(ntag, data[it]) if data[it]
108
102
  end
109
103
  end
110
104
 
111
- data.each do |k,v|
105
+ data.each do |k, v|
112
106
  next unless v
107
+
113
108
  ary = v.scan(re).flatten
114
109
  i = 0
115
110
  if ary and ary.size > 0
116
111
  except_ary.each do |it|
117
- unless ary.index(it)
118
- i += 1
119
- end
112
+ i += 1 unless ary.index(it)
120
113
  end
121
114
  end
122
115
  if i > 0
@@ -128,15 +121,13 @@ module Ykutils
128
121
  data
129
122
  end
130
123
 
131
- def make_data_complement(item_ary, data , common )
124
+ def make_data_complement(item_ary, data, common)
132
125
  item_ary.each do |it|
133
- unless data[it] and data[it].strip != ""
134
- data[it] = common[it]
135
- end
126
+ data[it] = common[it] unless data[it] and data[it].strip != ""
136
127
  end
137
128
  end
138
129
 
139
- def check_data_complement( item_ary , data )
130
+ def check_data_complement(item_ary, _data)
140
131
  mes_ary = []
141
132
  item_ary.each do |k|
142
133
  unless @data[k]
@@ -147,62 +138,62 @@ module Ykutils
147
138
  mes_ary
148
139
  end
149
140
 
150
- def check_data_complement_print_message( item_ary , data )
151
- mes_ary = check_data_complement( item_ary , data )
141
+ def check_data_complement_print_message(item_ary, data)
142
+ mes_ary = check_data_complement(item_ary, data)
152
143
  mes_ary.each do |mes|
153
144
  puts mes
154
145
  end
155
146
  end
156
-
157
- def load_csv_file( fname )
147
+
148
+ def load_csv_file(fname)
158
149
  ary = []
159
150
  begin
160
- CSV.open( fname , 'r') do |row|
151
+ CSV.open(fname, "r") do |row|
161
152
  next unless row
162
-
153
+
163
154
  ary << row[0]
164
155
  end
165
- rescue => ex
166
- pp ex
167
- pp ex.backtrace
156
+ rescue StandardError => e
157
+ pp e
158
+ pp e.backtrace
168
159
  @valid = false
169
160
  end
170
161
  ary
171
162
  end
172
163
 
173
- def load_csv_file_ex( fname )
164
+ def load_csv_file_ex(fname)
174
165
  ary = []
175
166
  begin
176
- CSV.open( fname , 'r') do |row|
167
+ CSV.open(fname, "r") do |row|
177
168
  next unless row
178
-
179
- ary.concat( row )
169
+
170
+ ary.concat(row)
180
171
  end
181
- rescue => ex
182
- pp ex
183
- pp ex.backtrace
172
+ rescue StandardError => e
173
+ pp e
174
+ pp e.backtrace
184
175
  @valid = false
185
176
  end
186
177
  ary
187
178
  end
188
179
 
189
- def load_plain_text_file( fname )
180
+ def load_plain_text_file(fname)
190
181
  ary = []
191
182
 
192
183
  begin
193
184
  ary0 = File.readlines(fname)
194
- senc = NKFUTIL.auto_config_to_inner( ary0.join )
185
+ senc = NKFUTIL.auto_config_to_inner(ary0.join)
195
186
 
196
- ary = ary0.select{ |x| x != nil }.collect{ |x|
197
- if x != nil then
198
- NKFUTIL.convert( x )
199
- else
200
- ""
187
+ ary = ary0.select { |x| !x.nil? }.collect do |x|
188
+ if x.nil?
189
+ ""
190
+ else
191
+ NKFUTIL.convert(x)
201
192
  end
202
- }
203
- rescue => ex
204
- pp ex
205
- pp ex.backtrace
193
+ end
194
+ rescue StandardError => e
195
+ pp e
196
+ pp e.backtrace
206
197
  @valid = false
207
198
 
208
199
  ary = []