chupa-text-decomposer-spreadsheet 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/chupa-text-decomposer-spreadsheet.gemspec +1 -1
- data/doc/text/news.md +6 -0
- data/lib/chupa-text/decomposers/spreadsheet.rb +33 -1
- data/test/test-spreadsheet.rb +18 -18
- 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: 22f7ed80714972494477908f60a89674bdc00cb83ca3c1f1ec5cd424edbd859f
|
4
|
+
data.tar.gz: 1e7c033e57c15fd6064023250358dd7ea61d079a31c2c5982957ce2faff63401
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e7e17be84e4102a02167f1803c83579e59ad5fb79a0a257f39904f0b8d1a452651a433d0a1981b451ae108d78b7cddc9036d24edd67c82366cda46b2ebcf0f5
|
7
|
+
data.tar.gz: a9e9afc0db8c66628003df03d640b40e2ff502f00640934b1540ea41cea4bfb9278c261781b6d0c6e2aa916a362f48ca96206b8c0c400d1210b188542080599c
|
data/doc/text/news.md
CHANGED
@@ -34,7 +34,7 @@ module ChupaText
|
|
34
34
|
open_book(data) do |book|
|
35
35
|
book.sheets.each do |sheet_name|
|
36
36
|
sheet = book.sheet(sheet_name)
|
37
|
-
body = sheet
|
37
|
+
body = build_body(sheet)
|
38
38
|
text_data = TextData.new(body, source_data: data)
|
39
39
|
text_data["name"] = sheet_name
|
40
40
|
text_data["digest"] = Digest::SHA1.hexdigest(body)
|
@@ -70,6 +70,38 @@ module ChupaText
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
+
def build_body(sheet)
|
74
|
+
body = ""
|
75
|
+
first_row = sheet.first_row
|
76
|
+
return body if first_row.nil?
|
77
|
+
|
78
|
+
1.upto(sheet.last_row) do |row|
|
79
|
+
1.upto(sheet.last_column) do |column|
|
80
|
+
body << "\t" if column > 1
|
81
|
+
body << build_cell(sheet, row, column)
|
82
|
+
end
|
83
|
+
body << "\n"
|
84
|
+
end
|
85
|
+
|
86
|
+
body
|
87
|
+
end
|
88
|
+
|
89
|
+
def build_cell(sheet, row, column)
|
90
|
+
return "" if sheet.empty?(row, column)
|
91
|
+
|
92
|
+
cell = sheet.cell(row, column)
|
93
|
+
case sheet.celltype(row, column)
|
94
|
+
when :string
|
95
|
+
cell
|
96
|
+
when :time
|
97
|
+
sheet.integer_to_timestring(cell)
|
98
|
+
when :link
|
99
|
+
cell.url
|
100
|
+
else
|
101
|
+
cell.to_s
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
73
105
|
def log_tag
|
74
106
|
"[decomposer][spreadsheet]"
|
75
107
|
end
|
data/test/test-spreadsheet.rb
CHANGED
@@ -19,28 +19,28 @@ class TestSpreadsheet < Test::Unit::TestCase
|
|
19
19
|
|
20
20
|
def test_ods
|
21
21
|
assert_equal([<<-SHEET1, <<-SHEET2, <<-SHEET3],
|
22
|
-
|
23
|
-
|
22
|
+
Sheet1 - A1\tSheet1 - B1
|
23
|
+
Sheet1 - A2\tSheet1 - B2
|
24
24
|
SHEET1
|
25
|
-
|
26
|
-
|
25
|
+
Sheet2 - A1\tSheet2 - B1
|
26
|
+
Sheet2 - A2\tSheet2 - B2
|
27
27
|
SHEET2
|
28
|
-
|
29
|
-
|
28
|
+
Sheet3 - A1\tSheet3 - B1
|
29
|
+
Sheet3 - A2\tSheet3 - B2
|
30
30
|
SHEET3
|
31
31
|
decompose("ods/multi-sheets.ods"))
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_xls
|
35
35
|
assert_equal([<<-SHEET1, <<-SHEET2, <<-SHEET3],
|
36
|
-
|
37
|
-
|
36
|
+
Sheet1 - A1\tSheet1 - B1
|
37
|
+
Sheet1 - A2\tSheet1 - B2
|
38
38
|
SHEET1
|
39
|
-
|
40
|
-
|
39
|
+
Sheet2 - A1\tSheet2 - B1
|
40
|
+
Sheet2 - A2\tSheet2 - B2
|
41
41
|
SHEET2
|
42
|
-
|
43
|
-
|
42
|
+
Sheet3 - A1\tSheet3 - B1
|
43
|
+
Sheet3 - A2\tSheet3 - B2
|
44
44
|
SHEET3
|
45
45
|
decompose("xls/multi-sheets.xls"))
|
46
46
|
end
|
@@ -61,14 +61,14 @@ class TestSpreadsheet < Test::Unit::TestCase
|
|
61
61
|
|
62
62
|
def test_xlsx
|
63
63
|
assert_equal([<<-SHEET1, <<-SHEET2, <<-SHEET3],
|
64
|
-
|
65
|
-
|
64
|
+
Sheet1 - A1\tSheet1 - B1
|
65
|
+
Sheet1 - A2\tSheet1 - B2
|
66
66
|
SHEET1
|
67
|
-
|
68
|
-
|
67
|
+
Sheet2 - A1\tSheet2 - B1
|
68
|
+
Sheet2 - A2\tSheet2 - B2
|
69
69
|
SHEET2
|
70
|
-
|
71
|
-
|
70
|
+
Sheet3 - A1\tSheet3 - B1
|
71
|
+
Sheet3 - A2\tSheet3 - B2
|
72
72
|
SHEET3
|
73
73
|
decompose("xlsx/multi-sheets.xlsx"))
|
74
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chupa-text-decomposer-spreadsheet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenji Okimoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chupa-text
|