spreadbase 0.2.0 → 0.2.1

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: 603c441b06a1eb85d926da95f9ce1c384fcd1642402e786fa7fc6106cd2e6def
4
- data.tar.gz: 973d5b1f2908261266e760b028f7cc884e5c9e9ba651488d9c7396f9d39ec688
3
+ metadata.gz: c697a87553389d94f16ea79fbcb0552ddea9dd7e18b13404078cca8b0d13b32d
4
+ data.tar.gz: 05b540a328ee21d7263b4f3b619dd6799641d4ca04ef2d99b694ec6d75b243a5
5
5
  SHA512:
6
- metadata.gz: 99e574f21843aa28699d5732942165e11f5b213a3dfe932f365b4f9bd0c0798fca7b4b49a84a755e2d9dbfabdfacab5cc3a840eb727ef09a9890d8f1255d470e
7
- data.tar.gz: 1fbe613fa5c63cd02853ce36d8d423a2597ab536e560c6c14f79ca9e5c7b247fc9f643b7390561221c20346f54ac72954048b3d9e5f2e90b64f4b7f4c2718cfe
6
+ metadata.gz: e94b944ff92895cb2f090c7c8b4ca2b0ce84eee4ffd2c9cb855047f430992ed60bfa6dbf39f336414887a4f12b02c3ce1dc0857ae7293e071514a9360c7f2334
7
+ data.tar.gz: 32c1bf438e40c8a5b4a321160f3931c3afae5fe1f455946fe2912c1ea26c2f423ba57af0b0cb06b92f7470db12656bc047180eabed82416664bd6e0d176884c1
@@ -0,0 +1,25 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ rspec:
7
+ runs-on: ubuntu-latest
8
+
9
+ strategy:
10
+ matrix:
11
+ ruby: ['3.0', '2.7', '2.6', '2.5', '2.4', '2.3']
12
+
13
+ steps:
14
+ - name: Checkout spreadbase repository
15
+ uses: actions/checkout@v2
16
+
17
+ - name: Setup Ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: ${{ matrix.ruby }}
21
+ bundler-cache: true
22
+
23
+ - name: Run RSpec
24
+ run: |
25
+ bundle exec rake spec
data/Gemfile CHANGED
@@ -1,3 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
+
5
+ if Gem.ruby_version >= Gem::Version.new('3.0.0')
6
+ gem 'rexml'
7
+ end
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Build Status][BS img]](https://travis-ci.org/saveriomiroddi/spreadbase)
1
+ [![CI](https://github.com/saveriomiroddi/spreadbase/actions/workflows/ci.yml/badge.svg)](https://github.com/saveriomiroddi/spreadbase/actions/workflows/ci.yml)
2
2
 
3
3
  SpreadBase!!
4
4
  ============
@@ -154,5 +154,3 @@ Roadmap/Todo
154
154
  ------------
155
155
 
156
156
  https://github.com/saveriomiroddi/spreadbase/wiki/Todo-%28roadmap%29
157
-
158
- [BS img]: https://travis-ci.org/saveriomiroddi/spreadbase.svg?branch=master
@@ -59,7 +59,7 @@ module SpreadBase # :nodoc:
59
59
  # A single column/row can represent multiple columns (table:number-(columns|rows)-repeated)
60
60
  #
61
61
  table.column_width_styles = column_nodes.inject([]) { | current_styles, node | current_styles + decode_column_width_style(node) }
62
- table.data = row_nodes.inject([]) { | current_rows, node | current_rows + decode_row_node(node, options) }
62
+ table.data = decode_row_nodes(row_nodes, options)
63
63
 
64
64
  table
65
65
  end
@@ -73,23 +73,48 @@ module SpreadBase # :nodoc:
73
73
  make_array_from_repetitions(style_name, repetitions)
74
74
  end
75
75
 
76
+ def decode_row_nodes(row_nodes, options)
77
+ rows = []
78
+ row_nodes.inject(0) do |size, node|
79
+ row, repetitions = decode_row_node(node, options)
80
+ row.empty? || append_row(rows, size, row, repetitions)
81
+ size + repetitions
82
+ end
83
+ rows
84
+ end
85
+
76
86
  def decode_row_node(row_node, options)
77
87
  repetitions = (row_node.attributes['table:number-rows-repeated'] || '1').to_i
78
88
  cell_nodes = row_node.elements.to_a('table:table-cell')
79
89
 
80
- # Watch out the :flatten; a single cell can represent multiple cells (table:number-columns-repeated)
81
- #
82
- values = cell_nodes.map { | node | decode_cell_node(node, options) }.flatten
90
+ [decode_cell_nodes(cell_nodes, options), repetitions]
91
+ end
83
92
 
84
- make_array_from_repetitions(values, repetitions)
93
+ def append_row(rows, size, row, repetitions)
94
+ (size - rows.size).times { rows << [] }
95
+ rows.concat(make_array_from_repetitions(row, repetitions))
85
96
  end
86
97
 
87
- def decode_cell_node(cell_node, options)
88
- value = decode_cell_value(cell_node, options)
98
+ def decode_cell_nodes(cell_nodes, options)
99
+ cells = []
100
+ cell_nodes.inject(0) do |size, node|
101
+ cell, repetitions = decode_cell_node(node, options)
102
+ cell.nil? || append_cell(cells, size, cell, repetitions)
103
+ size + repetitions
104
+ end
105
+ cells
106
+ end
89
107
 
90
- repetitions = (cell_node.attributes['table:number-columns-repeated'] || '1').to_i
108
+ def decode_cell_node(cell_node, options)
109
+ [
110
+ decode_cell_value(cell_node, options),
111
+ (cell_node.attributes['table:number-columns-repeated'] || '1').to_i
112
+ ]
113
+ end
91
114
 
92
- make_array_from_repetitions(value, repetitions)
115
+ def append_cell(cells, size, cell, repetitions)
116
+ cells[size - 1] = nil if size != cells.size
117
+ cells.concat(make_array_from_repetitions(cell, repetitions))
93
118
  end
94
119
 
95
120
  def decode_cell_value(cell_node, options)
@@ -1,3 +1,3 @@
1
1
  module SpreadBase
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -15,7 +15,7 @@ describe SpreadBase::Codecs::OpenDocument12 do
15
15
  'abc', [
16
16
  [1, 1.1, T_BIGDECIMAL],
17
17
  [T_DATE, T_DATETIME, T_TIME],
18
- [nil, 'a', nil]
18
+ [nil, nil, 'a']
19
19
  ]
20
20
  )
21
21
 
@@ -56,8 +56,8 @@ describe SpreadBase::Codecs::OpenDocument12 do
56
56
 
57
57
  assert_size(row_3, 3) do | value_1, value_2, value_3 |
58
58
  expect(value_1).to eq(nil)
59
- expect(value_2).to eq('a')
60
- expect(value_3).to eq(nil)
59
+ expect(value_2).to eq(nil)
60
+ expect(value_3).to eq('a')
61
61
  end
62
62
 
63
63
  end
@@ -112,4 +112,90 @@ describe SpreadBase::Codecs::OpenDocument12 do
112
112
  expect(value).to eq(T_BIGDECIMAL)
113
113
  end
114
114
 
115
+ context "when cells at the end of the row are empty" do
116
+ let(:document_archive) do
117
+ document = SpreadBase::Document.new
118
+
119
+ document.tables << SpreadBase::Table.new(
120
+ 'abc', [
121
+ [nil],
122
+ [nil, nil],
123
+ [1 , nil],
124
+ [nil, 1 , nil]
125
+ ]
126
+ )
127
+
128
+ SpreadBase::Codecs::OpenDocument12.new.encode_to_archive(document)
129
+ end
130
+
131
+ it "should drop such cells" do
132
+ document = SpreadBase::Codecs::OpenDocument12.new.decode_archive(document_archive)
133
+ table = document.tables[0]
134
+
135
+ assert_size(table.data, 4) do |row_1, row_2, row_3, row_4|
136
+ assert_size(row_1, 0)
137
+
138
+ assert_size(row_2, 0)
139
+
140
+ assert_size(row_3, 1) do |value_1|
141
+ expect(value_1).to eq(1)
142
+ end
143
+
144
+ assert_size(row_4, 2) do |value_1, value_2|
145
+ expect(value_1).to be_nil
146
+ expect(value_2).to eq(1)
147
+ end
148
+ end
149
+ end
150
+ end
151
+
152
+ context "when cells of the last row are empty" do
153
+ let(:document_archive) do
154
+ document = SpreadBase::Document.new
155
+
156
+ document.tables << SpreadBase::Table.new(
157
+ 'abc', [
158
+ []
159
+ ]
160
+ )
161
+
162
+ document.tables << SpreadBase::Table.new(
163
+ 'def', [
164
+ [nil]
165
+ ]
166
+ )
167
+
168
+ document.tables << SpreadBase::Table.new(
169
+ 'ghi', [
170
+ [nil, nil]
171
+ ]
172
+ )
173
+
174
+ document.tables << SpreadBase::Table.new(
175
+ 'jkl', [
176
+ [nil],
177
+ [1],
178
+ [nil]
179
+ ]
180
+ )
181
+
182
+ SpreadBase::Codecs::OpenDocument12.new.encode_to_archive(document)
183
+ end
184
+
185
+ it "should drop such row" do
186
+ document = SpreadBase::Codecs::OpenDocument12.new.decode_archive(document_archive)
187
+ tables = document.tables
188
+
189
+ assert_size(tables, 4) do |table_1, table_2, table_3, table_4|
190
+ assert_size(table_1.data, 0)
191
+
192
+ assert_size(table_2.data, 0)
193
+
194
+ assert_size(table_3.data, 0)
195
+
196
+ assert_size(table_4.data, 2)
197
+ end
198
+ end
199
+ end
200
+
115
201
  end
@@ -109,4 +109,27 @@ abc:
109
109
  expect(@sample_document.to_s(with_headers: true)).to eq(expected_string)
110
110
  end
111
111
 
112
+ it "should parse a existing ODS file" do
113
+ ods_file = File.expand_path('../fixtures/test.ods', __dir__)
114
+ document = SpreadBase::Document.new(ods_file)
115
+
116
+ expect(document.tables[0].name).to eq('Sheet1')
117
+ expect(document.tables[0].data).to match([
118
+ match(['hoge' ]),
119
+ match([nil , 'fuga' ]),
120
+ match([nil , nil , 'piyo' ]),
121
+ match([nil , nil , nil , 'hogera' ]),
122
+ match([nil , nil , nil , nil , 'hogehoge'])
123
+ ])
124
+
125
+ expect(document.tables[1].name).to eq('Sheet2')
126
+ expect(document.tables[1].data).to match([
127
+ match([nil , nil , nil , nil , 'foo']),
128
+ match([nil , nil , nil , 'bar' ]),
129
+ match([nil , nil , 'baz' ]),
130
+ match([nil , 'foobar' ]),
131
+ match(['qux' ])
132
+ ])
133
+ end
134
+
112
135
  end
Binary file
data/spreadbase.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.required_ruby_version = '>= 2.3.0'
12
12
  s.authors = ["Saverio Miroddi"]
13
- s.date = '2020-07-15'
13
+ s.date = '2021-03-05'
14
14
  s.email = ["saverio.pub2@gmail.com"]
15
15
  s.homepage = "https://github.com/saveriomiroddi/spreadbase"
16
16
  s.summary = %q{Library for reading/writing OpenOffice Calc documents.}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spreadbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saverio Miroddi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-15 00:00:00.000000000 Z
11
+ date: 2021-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -59,9 +59,9 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - ".github/workflows/ci.yml"
62
63
  - ".gitignore"
63
64
  - ".rspec"
64
- - ".travis.yml"
65
65
  - Gemfile
66
66
  - LICENSE
67
67
  - README.md
@@ -80,6 +80,7 @@ files:
80
80
  - spec/codecs/open_document_12_spec.rb
81
81
  - spec/elements/document_spec.rb
82
82
  - spec/elements/table_spec.rb
83
+ - spec/fixtures/test.ods
83
84
  - spec/spec_helper.rb
84
85
  - spec/spec_helpers.rb
85
86
  - spreadbase.gemspec
@@ -107,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
108
  - !ruby/object:Gem::Version
108
109
  version: '0'
109
110
  requirements: []
110
- rubygems_version: 3.0.8
111
+ rubygems_version: 3.2.3
111
112
  signing_key:
112
113
  specification_version: 4
113
114
  summary: Library for reading/writing OpenOffice Calc documents.
data/.travis.yml DELETED
@@ -1,8 +0,0 @@
1
- dist: bionic
2
- language: ruby
3
- rvm:
4
- - 2.3
5
- - 2.4
6
- - 2.5
7
- - 2.6
8
- - 2.7