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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b50a60537eb1f3f662b6f71da4ea8d29a85301d593b9dfbac4da2211c73017d4
4
- data.tar.gz: e8ebf3da90b055a6a987409466d02013105fc3e48fb3eb5044a2fe1e81d41807
3
+ metadata.gz: 22f7ed80714972494477908f60a89674bdc00cb83ca3c1f1ec5cd424edbd859f
4
+ data.tar.gz: 1e7c033e57c15fd6064023250358dd7ea61d079a31c2c5982957ce2faff63401
5
5
  SHA512:
6
- metadata.gz: eb709a20b9b5205653507304506b36e86e321def5d7846113822396121a50f32b61739ce88cab30573a8593bca02715e3fee57d2a588ee26e9fc96116c2fd2ea
7
- data.tar.gz: '04315366589a40e543c6ef17808c7d902b135924bea0a5ce1b8df0b4bdf2be349a30c23eb30c9bc4391ea0e21abaaabd9982f64507e178bd294b8609776917ae'
6
+ metadata.gz: 1e7e17be84e4102a02167f1803c83579e59ad5fb79a0a257f39904f0b8d1a452651a433d0a1981b451ae108d78b7cddc9036d24edd67c82366cda46b2ebcf0f5
7
+ data.tar.gz: a9e9afc0db8c66628003df03d640b40e2ff502f00640934b1540ea41cea4bfb9278c261781b6d0c6e2aa916a362f48ca96206b8c0c400d1210b188542080599c
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "chupa-text-decomposer-spreadsheet"
5
- spec.version = "1.0.4"
5
+ spec.version = "1.0.5"
6
6
  spec.author = "Kenji Okimoto"
7
7
  spec.email = "okimoto@clear-code.com"
8
8
  spec.summary = "ChupaText decomposer for spreadsheet."
@@ -1,5 +1,11 @@
1
1
  # News
2
2
 
3
+ ## 1.0.5: 2019-03-28
4
+
5
+ ### Improvements
6
+
7
+ * Simplified extracted text.
8
+
3
9
  ## 1.0.4: 2019-03-01
4
10
 
5
11
  ### Improvements
@@ -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.to_csv
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
@@ -19,28 +19,28 @@ class TestSpreadsheet < Test::Unit::TestCase
19
19
 
20
20
  def test_ods
21
21
  assert_equal([<<-SHEET1, <<-SHEET2, <<-SHEET3],
22
- "Sheet1 - A1","Sheet1 - B1"
23
- "Sheet1 - A2","Sheet1 - B2"
22
+ Sheet1 - A1\tSheet1 - B1
23
+ Sheet1 - A2\tSheet1 - B2
24
24
  SHEET1
25
- "Sheet2 - A1","Sheet2 - B1"
26
- "Sheet2 - A2","Sheet2 - B2"
25
+ Sheet2 - A1\tSheet2 - B1
26
+ Sheet2 - A2\tSheet2 - B2
27
27
  SHEET2
28
- "Sheet3 - A1","Sheet3 - B1"
29
- "Sheet3 - A2","Sheet3 - B2"
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
- "Sheet1 - A1","Sheet1 - B1"
37
- "Sheet1 - A2","Sheet1 - B2"
36
+ Sheet1 - A1\tSheet1 - B1
37
+ Sheet1 - A2\tSheet1 - B2
38
38
  SHEET1
39
- "Sheet2 - A1","Sheet2 - B1"
40
- "Sheet2 - A2","Sheet2 - B2"
39
+ Sheet2 - A1\tSheet2 - B1
40
+ Sheet2 - A2\tSheet2 - B2
41
41
  SHEET2
42
- "Sheet3 - A1","Sheet3 - B1"
43
- "Sheet3 - A2","Sheet3 - B2"
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
- "Sheet1 - A1","Sheet1 - B1"
65
- "Sheet1 - A2","Sheet1 - B2"
64
+ Sheet1 - A1\tSheet1 - B1
65
+ Sheet1 - A2\tSheet1 - B2
66
66
  SHEET1
67
- "Sheet2 - A1","Sheet2 - B1"
68
- "Sheet2 - A2","Sheet2 - B2"
67
+ Sheet2 - A1\tSheet2 - B1
68
+ Sheet2 - A2\tSheet2 - B2
69
69
  SHEET2
70
- "Sheet3 - A1","Sheet3 - B1"
71
- "Sheet3 - A2","Sheet3 - B2"
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
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-01 00:00:00.000000000 Z
11
+ date: 2019-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chupa-text