yomise 0.1.3 → 0.1.4
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/.rspec +3 -3
- data/CODE_OF_CONDUCT.md +84 -84
- data/Gemfile +9 -10
- data/LICENSE.txt +21 -21
- data/README.md +39 -39
- data/Rakefile +8 -8
- data/lib/longest_line.rb +16 -4
- data/lib/to_csv.rb +120 -112
- data/lib/yomise/version.rb +5 -5
- data/lib/yomise.rb +321 -290
- data/sig/yomise.rbs +4 -4
- data/yomise.gemspec +46 -0
- metadata +18 -3
data/lib/yomise.rb
CHANGED
|
@@ -1,290 +1,321 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
require "csv"
|
|
3
|
-
require "roo-xls"
|
|
4
|
-
require "spreadsheet"
|
|
5
|
-
require "rover"
|
|
6
|
-
require "daru"
|
|
7
|
-
require_relative "./to_csv"
|
|
8
|
-
require_relative "./longest_line"
|
|
9
|
-
require_relative "yomise/version"
|
|
10
|
-
|
|
11
|
-
module Yomise
|
|
12
|
-
class Error < StandardError; end
|
|
13
|
-
|
|
14
|
-
module_function
|
|
15
|
-
|
|
16
|
-
def read(path, **opt)
|
|
17
|
-
return /csv$/i === path ? read_csv(path, **opt) : read_excel(path, **opt)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# ##Generate Array from CSV File, and convert it to Hash or DataFrame.
|
|
21
|
-
# **opt candidate= line_from: 1, header: 0
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
##
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
#
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
#
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return
|
|
68
|
-
elsif format.to_s == "
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return
|
|
101
|
-
elsif format.to_s == "
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
#
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
#
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
#
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
#
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require "csv"
|
|
3
|
+
require "roo-xls"
|
|
4
|
+
require "spreadsheet"
|
|
5
|
+
require "rover"
|
|
6
|
+
require "daru"
|
|
7
|
+
require_relative "./to_csv"
|
|
8
|
+
require_relative "./longest_line"
|
|
9
|
+
require_relative "yomise/version"
|
|
10
|
+
|
|
11
|
+
module Yomise
|
|
12
|
+
class Error < StandardError; end
|
|
13
|
+
|
|
14
|
+
module_function
|
|
15
|
+
|
|
16
|
+
def read(path, **opt)
|
|
17
|
+
return /csv$/i === path ? read_csv(path, **opt) : read_excel(path, **opt)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# ##Generate Array from CSV File, and convert it to Hash or DataFrame.
|
|
21
|
+
# **opt candidate= line_from: 1, header: 0
|
|
22
|
+
def read_csv(path, format: :rover, encoding: "utf-8", liberal_parsing: true, reconvert_utf8: false, col_sep: ",", index: nil, **opt)
|
|
23
|
+
## TODO.. index: option that designate column number to generate DF index.
|
|
24
|
+
## That is, revicing set_index method.
|
|
25
|
+
|
|
26
|
+
# Get 2D Array
|
|
27
|
+
begin
|
|
28
|
+
if liberal_parsing
|
|
29
|
+
csvd = CSV.read(path, encoding: encoding, liberal_parsing: true)
|
|
30
|
+
if encoding.to_s.downcase != "utf-8"
|
|
31
|
+
csv = csvd.to_a.map {|l| l.map {|cell| cell.nil? ? nil : cell.encode("utf-8", invalid: :replace, replace: '') }}
|
|
32
|
+
else
|
|
33
|
+
csv = csvd
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
encoding = "utf-8"
|
|
37
|
+
else
|
|
38
|
+
# Old style (Not Recommended)
|
|
39
|
+
# This "&:read" is not Yomise's function(defined avobe here).. parhaps File's method.
|
|
40
|
+
csv = CSV.parse(File.open(path, encoding: encoding, &:read), col_sep: col_sep)
|
|
41
|
+
end
|
|
42
|
+
rescue
|
|
43
|
+
# Try Another Encoding
|
|
44
|
+
## puts "Fail Encoding #{encoding}. Trying cp932..."
|
|
45
|
+
if liberal_parsing
|
|
46
|
+
csvd = CSV.read(path, encoding: "cp932", liberal_parsing: true)
|
|
47
|
+
if encoding.to_s.downcase != "utf-8"
|
|
48
|
+
csv = csvd.to_a.map {|l| l.map {|cell| cell.nil? ? nil : cell.encode("utf-8", invalid: :replace, replace: '') }}
|
|
49
|
+
else
|
|
50
|
+
csv = csvd
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
encoding = "UTF-8"
|
|
54
|
+
else
|
|
55
|
+
# Old style (Not Recommended)
|
|
56
|
+
# This "&:read" is not Yomise's function(defined avobe here).. parhaps File's method.
|
|
57
|
+
csv = CSV.parse(File.open(path, encoding: "cp932", &:read), col_sep: col_sep)
|
|
58
|
+
end
|
|
59
|
+
encoding = "cp932"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
if reconvert_utf8
|
|
63
|
+
csv = csv.map {|l| l.map {|cell| cell.nil? ? nil : cell.encode("UTF-8")}}
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
if format.to_s == "array"
|
|
67
|
+
return csv
|
|
68
|
+
elsif format.to_s == "hash"
|
|
69
|
+
h, i = to_hash(csv, **opt)
|
|
70
|
+
return h
|
|
71
|
+
elsif format.to_s == "csv"
|
|
72
|
+
return csv.to_csv
|
|
73
|
+
elsif format.to_s == "numo"
|
|
74
|
+
return csv # Under Construction
|
|
75
|
+
else # include format.nil? (in this case, convert to Daru::DF).
|
|
76
|
+
|
|
77
|
+
h, ind_orig = to_hash(csv, index: index, **opt)
|
|
78
|
+
ans = to_df(h, format: format)
|
|
79
|
+
|
|
80
|
+
# Converting Encode and Setting index.. rover not supported yet
|
|
81
|
+
if format.to_s == "daru"
|
|
82
|
+
ans.convert_enc!(from: encoding, to: "utf-8") if encoding.to_s.downcase != "utf-8"
|
|
83
|
+
begin
|
|
84
|
+
ans.index = ind_orig if index
|
|
85
|
+
rescue
|
|
86
|
+
warn "Indexing failed (Parhaps due to duplicated index)."
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
return ans
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# ##Generate Array from EXCEL File, and convert it to Hash or DataFrame.
|
|
95
|
+
# **opt candidate= line_from: 1, header: 0)
|
|
96
|
+
def read_excel(path, sheet_i: 0, format: :rover, encoding: "utf-8", index: nil, **opt)
|
|
97
|
+
a2d = open_excel(path, sheet_i, encoding: encoding) # Get 2D Array
|
|
98
|
+
|
|
99
|
+
if format.to_s == "array"
|
|
100
|
+
return a2d
|
|
101
|
+
elsif format.to_s == "hash"
|
|
102
|
+
h, i = to_hash(a2d, **opt)
|
|
103
|
+
return h
|
|
104
|
+
elsif format.to_s == "csv"
|
|
105
|
+
return a2d.to_csv
|
|
106
|
+
elsif format.to_s == "numo"
|
|
107
|
+
return a2d # Under Construction
|
|
108
|
+
else # include format.nil?
|
|
109
|
+
h, ind_orig = to_hash(a2d, index: index, **opt)
|
|
110
|
+
ans = to_df(h, format: format)
|
|
111
|
+
if format.to_s == "daru"
|
|
112
|
+
begin
|
|
113
|
+
ans.index = ind_orig if index
|
|
114
|
+
rescue
|
|
115
|
+
warn "Indexing failed (Parhaps due to duplicated index)."
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
return ans
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Convert 2d Array to Hash
|
|
123
|
+
## header: nil -> Default Headers(:column1, column2,...) are generated.
|
|
124
|
+
## Option line_ignored, is not implemented yet.
|
|
125
|
+
def to_hash(array2d, line_from: 1, line_until: nil, line_ignored: nil,
|
|
126
|
+
column_from: nil, column_until: nil,
|
|
127
|
+
header: 0, symbol_header: false,
|
|
128
|
+
replaced_by_nil: [], analyze_type: true,
|
|
129
|
+
index: nil)
|
|
130
|
+
## TODO.. column_from: , column_until:
|
|
131
|
+
|
|
132
|
+
# Define Read Range------------
|
|
133
|
+
lfrom, luntil = line_from, line_until
|
|
134
|
+
lf_reg, lu_reg = line_from.kind_of?(Regexp), line_until.kind_of?(Regexp)
|
|
135
|
+
|
|
136
|
+
if lf_reg || lu_reg
|
|
137
|
+
lines_ary = array2d.map{ _1.join "," }
|
|
138
|
+
lfrom = lines_ary.find_index{ line_from === _1 } if lf_reg
|
|
139
|
+
luntil = (lines_ary.length-1) - lines_ary.reverse.find_index{ line_until === _1 } if lu_reg
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# And get originally array-----
|
|
143
|
+
output = array2d[lfrom...luntil]
|
|
144
|
+
# -----------------------------
|
|
145
|
+
|
|
146
|
+
# Then get data of index-------
|
|
147
|
+
ind_orig = index ? output.map{ _1[index] } : nil
|
|
148
|
+
# -----------------------------
|
|
149
|
+
|
|
150
|
+
# Selecct Column---------------
|
|
151
|
+
output = output.map { _1[column_from...column_until] } if column_from || column_until
|
|
152
|
+
|
|
153
|
+
# Define Data Array------------
|
|
154
|
+
output_transpose = output[0].zip(*output[1..])
|
|
155
|
+
output_transpose = fix_array(output_transpose, replaced_by_nil, analyze_type)
|
|
156
|
+
# -----------------------------
|
|
157
|
+
|
|
158
|
+
# Define Header----------------
|
|
159
|
+
if header
|
|
160
|
+
hd = check_header(array2d[header])[column_from...column_until]
|
|
161
|
+
else
|
|
162
|
+
hd = [*0...(output.longest_line)].map{"column#{_1}"}
|
|
163
|
+
end
|
|
164
|
+
# hd = header.nil? ? [*0...(output.longest_line)].map{"column#{_1}"} : check_header(array2d[header])
|
|
165
|
+
|
|
166
|
+
hd = hd.map { _1.intern } if symbol_header
|
|
167
|
+
# -----------------------------
|
|
168
|
+
|
|
169
|
+
# Make Hash(Header => Data Array)
|
|
170
|
+
return hd.each_with_object({}).with_index {|(hdr, hash), i| hash[hdr]=output_transpose[i]}, ind_orig
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
# Convert Hash to DataFrame
|
|
174
|
+
def to_df(d, format: :rover)
|
|
175
|
+
if format.to_s == "daru"
|
|
176
|
+
Daru::DataFrame.new(d)
|
|
177
|
+
else
|
|
178
|
+
Rover::DataFrame.new(d)
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
# Rover用: nil や nanを取り除くマスク、または二値の列(true-false value)生成
|
|
183
|
+
def is_available(value, truevalue: true, falsevalue: false, blank_str_is_false: true)
|
|
184
|
+
if value.nil?
|
|
185
|
+
falsevalue
|
|
186
|
+
else
|
|
187
|
+
if value.is_a? Numeric
|
|
188
|
+
!value.nan? ? truevalue : falsevalue
|
|
189
|
+
elsif value.is_a? String
|
|
190
|
+
if value == ""
|
|
191
|
+
blank_str_is_false ? falsevalue : truevalue
|
|
192
|
+
else
|
|
193
|
+
truevalue
|
|
194
|
+
end
|
|
195
|
+
else
|
|
196
|
+
truevalue
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def available(data, truevalue: true, falsevalue: false, blank_str_is_false: true)
|
|
202
|
+
if data.is_a? Rover::Vector
|
|
203
|
+
data.map { |v| is_available(v, truevalue: truevalue, falsevalue: falsevalue, blank_str_is_false: blank_str_is_false) }
|
|
204
|
+
elsif data.is_a? Rover::DataFrame
|
|
205
|
+
dfdata = data.keys.map {|k| data[k].map { |d| is_available(d, truevalue: truevalue, falsevalue: falsevalue, blank_str_is_false: blank_str_is_false) } }
|
|
206
|
+
Rover::DataFrame.new(data.keys.zip(dfdata).map{[_1, _2]}.to_h)
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
#----------------------------
|
|
211
|
+
# Private metods from here
|
|
212
|
+
#----------------------------
|
|
213
|
+
|
|
214
|
+
# Genarate Array from excel file
|
|
215
|
+
def open_excel(path, sheet_i, encoding: "utf-8")
|
|
216
|
+
if /xls(x|m)$/ === path
|
|
217
|
+
puts "Sorry, encoding option is not supported yet for xlsx file." if encoding != "utf-8"
|
|
218
|
+
|
|
219
|
+
book = Roo::Excelx.new(path)
|
|
220
|
+
s = book.sheet(sheet_i)
|
|
221
|
+
|
|
222
|
+
## bottole neck
|
|
223
|
+
return s.to_a
|
|
224
|
+
|
|
225
|
+
# xls
|
|
226
|
+
else
|
|
227
|
+
begin
|
|
228
|
+
Spreadsheet.client_encoding = encoding
|
|
229
|
+
ss = Spreadsheet.open(path)
|
|
230
|
+
rescue Encoding::InvalidByteSequenceError
|
|
231
|
+
puts "Fail Encoding #{encoding}. Trying Windows-31J..."
|
|
232
|
+
Spreadsheet.client_encoding = "Windows-31J"
|
|
233
|
+
ss = Spreadsheet.open(path)
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
a2d = []
|
|
237
|
+
ss.worksheets[sheet_i].rows.each do |row|
|
|
238
|
+
a1d = []
|
|
239
|
+
row.each {|cell| a1d.push cell}
|
|
240
|
+
a2d.push a1d
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
return a2d
|
|
244
|
+
end
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
# Fix Array (Replace specific values to nil, recognize value type and cast values to the type.)
|
|
248
|
+
def fix_array(array2d, replaced_by_nil, analyze_type)
|
|
249
|
+
ans = array2d
|
|
250
|
+
|
|
251
|
+
## Replace Blank or User-Selected Value
|
|
252
|
+
ans = ans.map do |column|
|
|
253
|
+
column.map { |cell| replaced_by_nil.include?(cell) || /^\s*$/ === cell ? nil : cell }
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
## Replace Number Values to Integer or Float
|
|
257
|
+
if analyze_type
|
|
258
|
+
ans = ans.map.with_index do |column, i|
|
|
259
|
+
type_of_column = :any
|
|
260
|
+
column.each { |cell| type_of_column = recognize_type(cell, type_of_column) }
|
|
261
|
+
|
|
262
|
+
# p type_of_column
|
|
263
|
+
case type_of_column
|
|
264
|
+
when :int
|
|
265
|
+
column.map { _1.nil? ? nil : _1.to_i }
|
|
266
|
+
when :float
|
|
267
|
+
column.map { _1.nil? ? nil : _1.to_f }
|
|
268
|
+
else
|
|
269
|
+
column
|
|
270
|
+
end
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
return ans
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
def recognize_type(str, expected)
|
|
278
|
+
return expected if str.nil?
|
|
279
|
+
|
|
280
|
+
order = {:any => 0, :int => 1, :float => 2, :string => 3}
|
|
281
|
+
if /^\s*(-|\+)?\d+\s*$/ === str
|
|
282
|
+
type_of_str = :int
|
|
283
|
+
elsif /^\s*(-|\+)?\d*\.\d*\s*$/ === str || /^\s*(-|\+)?(\d*\.\d+|\d+)(e|E)(-|\+)?\d+\s*$/ === str
|
|
284
|
+
type_of_str = :float
|
|
285
|
+
else
|
|
286
|
+
type_of_str = :string
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
# p "#{type_of_str}, #{str}" if order[type_of_str] > order[expected]
|
|
290
|
+
|
|
291
|
+
return order[type_of_str] > order[expected] ? type_of_str : expected
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
# Fix blank or duplicated header
|
|
295
|
+
def check_header(header_array)
|
|
296
|
+
# Check Blank
|
|
297
|
+
ans = header_array.map.with_index do |item, i|
|
|
298
|
+
if item.nil?
|
|
299
|
+
"column#{i}"
|
|
300
|
+
elsif item.kind_of?(String)
|
|
301
|
+
temp = /^\s*$/ === item ? "column#{i}" : item.gsub(/\s+/, "")
|
|
302
|
+
/^\d+$/ === temp ? "column#{i}" : temp
|
|
303
|
+
else
|
|
304
|
+
item.to_s
|
|
305
|
+
end
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
# Check Duplicated Value
|
|
309
|
+
dup_check = (0...(header_array.length)).group_by {|i| ans[i]}
|
|
310
|
+
dup_check.each do |item, i_s|
|
|
311
|
+
if i_s.length > 1
|
|
312
|
+
i_s.each_with_index {|i, index_in_i_s| ans[i] = "#{ans[i]}_#{index_in_i_s}"}
|
|
313
|
+
end
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
return ans
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
private_class_method :open_excel, :fix_array, :check_header
|
|
320
|
+
|
|
321
|
+
end
|
data/sig/yomise.rbs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
module Yomise
|
|
2
|
-
VERSION: String
|
|
3
|
-
# See the writing guide of rbs: https://github.com/ruby/rbs#guides
|
|
4
|
-
end
|
|
1
|
+
module Yomise
|
|
2
|
+
VERSION: String
|
|
3
|
+
# See the writing guide of rbs: https://github.com/ruby/rbs#guides
|
|
4
|
+
end
|