rbbt-util 5.32.25 → 5.32.26
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/lib/rbbt/tsv/excel.rb +16 -8
- data/test/rbbt/tsv/test_excel.rb +38 -4
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 072aa8b010c3f395051fd4e29f6ac22647944eec529bdf05be77ac6ad5260a37
|
|
4
|
+
data.tar.gz: d68843b2fe56019dd63165a34c97ec23d9e60933e4493bdb61f29985548bca69
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9d572a394b5736d8780021bc8ec65ba4381dc8cb84f111704854ce77ceca8da0ca72626e0144a04ab5c9b552a5566f4bdd553cad2a70050216fae231179beb95
|
|
7
|
+
data.tar.gz: ce51f8a4f0f5b4028148deb7fd3e57a4fbf5bb531f366378a2bae31354b799a66c6ba2768d9ae25578b3a0b09ee4e29f817f6ab768166bed39e4245b35a4a7e4
|
data/lib/rbbt/tsv/excel.rb
CHANGED
|
@@ -177,7 +177,7 @@ module TSV
|
|
|
177
177
|
|
|
178
178
|
sheet ||= "0"
|
|
179
179
|
workbook = RubyXL::Parser.parse file
|
|
180
|
-
if sheet &&
|
|
180
|
+
if sheet && sheet =~ /^\d+$/
|
|
181
181
|
sheet = workbook.worksheets.collect{|s| s.sheet_name }[sheet.to_i]
|
|
182
182
|
end
|
|
183
183
|
sheet_name = sheet
|
|
@@ -185,7 +185,9 @@ module TSV
|
|
|
185
185
|
|
|
186
186
|
TmpFile.with_file :extension => Misc.sanitize_filename(sheet_name.to_s) do |filename|
|
|
187
187
|
|
|
188
|
-
sheet =
|
|
188
|
+
sheet = sheet_name ? workbook[sheet_name] : workbook.worksheets.first
|
|
189
|
+
|
|
190
|
+
raise "No sheet #{sheet_name} found" if sheet.nil?
|
|
189
191
|
|
|
190
192
|
rows = []
|
|
191
193
|
|
|
@@ -217,21 +219,27 @@ module TSV
|
|
|
217
219
|
end
|
|
218
220
|
|
|
219
221
|
def self.write(tsv, file, options = {})
|
|
220
|
-
sheet = Misc.process_options options, :sheet
|
|
222
|
+
sheet, add_sheet = Misc.process_options options, :sheet, :add_sheet
|
|
221
223
|
|
|
222
224
|
fields, rows = TSV._excel_data(tsv, options)
|
|
223
225
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
226
|
+
if Open.exists?(file) && add_sheet
|
|
227
|
+
book = RubyXL::Parser.parse file
|
|
228
|
+
sheet1 = book.add_worksheet(sheet)
|
|
229
|
+
else
|
|
230
|
+
book = RubyXL::Workbook.new
|
|
231
|
+
sheet1 = book.worksheets.first
|
|
232
|
+
sheet1.sheet_name = sheet if sheet
|
|
233
|
+
end
|
|
227
234
|
|
|
228
235
|
fields.each_with_index do |e,i|
|
|
229
236
|
sheet1.add_cell(0, i, e)
|
|
230
|
-
end
|
|
237
|
+
end if fields
|
|
231
238
|
|
|
232
239
|
rows.each_with_index do |cells,i|
|
|
240
|
+
i += 1 if fields
|
|
233
241
|
cells.each_with_index do |e,j|
|
|
234
|
-
sheet1.add_cell(i
|
|
242
|
+
sheet1.add_cell(i, j, e)
|
|
235
243
|
end
|
|
236
244
|
end
|
|
237
245
|
|
data/test/rbbt/tsv/test_excel.rb
CHANGED
|
@@ -2,7 +2,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'test_helpe
|
|
|
2
2
|
require 'rbbt/tsv/excel'
|
|
3
3
|
|
|
4
4
|
class TestExcel < Test::Unit::TestCase
|
|
5
|
-
def
|
|
5
|
+
def test_xls
|
|
6
6
|
content =<<-EOF
|
|
7
7
|
#Id ValueA ValueB OtherID
|
|
8
8
|
row1 a|aa|aaa b Id1|Id2
|
|
@@ -19,7 +19,7 @@ row2 A B Id3
|
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
def
|
|
22
|
+
def test_xlsx
|
|
23
23
|
content =<<-EOF
|
|
24
24
|
#Id ValueA ValueB OtherID
|
|
25
25
|
row1 a|aa|aaa b Id1|Id2
|
|
@@ -36,7 +36,7 @@ row2 A B Id3
|
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
-
def
|
|
39
|
+
def test_excel
|
|
40
40
|
content =<<-EOF
|
|
41
41
|
#Id ValueA ValueB OtherID
|
|
42
42
|
row1 a|aa|aaa b Id1|Id2
|
|
@@ -63,7 +63,7 @@ row2 A B Id3
|
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
def
|
|
66
|
+
def test_excel_sheets
|
|
67
67
|
content =<<-EOF
|
|
68
68
|
#Id ValueA ValueB OtherID
|
|
69
69
|
row1 a|aa|aaa b Id1|Id2
|
|
@@ -133,5 +133,39 @@ row2 A B Id3
|
|
|
133
133
|
end
|
|
134
134
|
end
|
|
135
135
|
end
|
|
136
|
+
|
|
137
|
+
def test_excel_multi_sheets
|
|
138
|
+
content =<<-EOF
|
|
139
|
+
#Id ValueA ValueB OtherID
|
|
140
|
+
row1 a|aa|aaa b Id1|Id2
|
|
141
|
+
row2 A B Id3
|
|
142
|
+
EOF
|
|
143
|
+
|
|
144
|
+
TmpFile.with_file(content) do |filename|
|
|
145
|
+
tsv1 = TSV.open(filename, :sep => /\s+/)
|
|
146
|
+
tsv2 = tsv1.annotate(tsv1.dup)
|
|
147
|
+
tsv3 = tsv1.annotate(tsv1.dup)
|
|
148
|
+
|
|
149
|
+
tsv2["row2"] = [["AA"], ["BB"], ["Id4"]]
|
|
150
|
+
tsv3["row2"] = [["AAA"], ["BBB"], ["Id5"]]
|
|
151
|
+
|
|
152
|
+
TmpFile.with_file(nil, false, :extension => 'xlsx') do |excelfile|
|
|
153
|
+
tsv1.xlsx(excelfile, :sheet => "S1")
|
|
154
|
+
tsv2.xlsx(excelfile, :sheet => "S2", :add_sheet => true)
|
|
155
|
+
workbook = RubyXL::Parser.parse excelfile
|
|
156
|
+
|
|
157
|
+
assert_equal %w(S1 S2), workbook.worksheets.collect{|s| s.sheet_name}
|
|
158
|
+
|
|
159
|
+
new = TSV.excel(excelfile, :sheet => "S1")
|
|
160
|
+
assert_equal %w(row1 row2), new.keys.sort
|
|
161
|
+
assert_equal %w(A), new["row2"]["ValueA"]
|
|
162
|
+
|
|
163
|
+
new = TSV.excel(excelfile, :sheet => "S2")
|
|
164
|
+
assert_equal %w(row1 row2), new.keys.sort
|
|
165
|
+
assert_equal %w(AA), new["row2"]["ValueA"]
|
|
166
|
+
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
136
170
|
end
|
|
137
171
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rbbt-util
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 5.32.
|
|
4
|
+
version: 5.32.26
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Miguel Vazquez
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-11-
|
|
11
|
+
date: 2021-11-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|