spreadbase 0.4.0 → 0.5.0

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: 37e52d4079a3f0f7c0ba6fef6db24dbe8426f1f47d66904ea9fa418744719e27
4
- data.tar.gz: 79304c560419b6500e95f9c4fb5c8d8bfbf9ffe3ed1b591125ab696be5652560
3
+ metadata.gz: 0c25a3b806d510bde0b396fc5dcb9443f2a909493a8b3bd850078a63539fc189
4
+ data.tar.gz: 76b76fe5242a2626c170f3b032c5ba6b26d500ec00cd72ceba813aa418c0335d
5
5
  SHA512:
6
- metadata.gz: c02992b1b27f909a4df2bc93df27965b90277d0343bed2a5c0cb88c99e8ff337146ba6239aa5764f826833e2ebde0793ac20ce0170afa473b9e78796c361e38f
7
- data.tar.gz: c02bbb08fe16bbb8dff403fac1948bc2f3457f544408c9e5bbd996fd90dbe3d4df6a68ad766f0217592f10823773bd0cdf307210b259ff1690c7ecf02ffadad9
6
+ metadata.gz: 37098ecaa48b14abb507edab85965d9383a1caf292e279eb970cf000c9edc3b68f30b6d4f1c75378b3497a48b00de9999bff60da2c45873db3ce0e20339c4c90
7
+ data.tar.gz: e9829cad4842d6219199a0ee2f0f3798997bc37f67fb4021c0d415e2f0e89579dd7ab81f6459fa690a096818c889c483ce8a4f250e93e78bb9f1d37ca23517b8
@@ -1,6 +1,9 @@
1
1
  name: CI
2
2
 
3
- on: [push, pull_request]
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
4
7
 
5
8
  jobs:
6
9
  rspec:
@@ -8,11 +11,12 @@ jobs:
8
11
 
9
12
  strategy:
10
13
  matrix:
11
- ruby: ['3.1', '3.0', '2.7', '2.6', '2.5', '2.4']
14
+ ruby: [head, '3.3', '3.2', '3.1', '3.0']
15
+ fail-fast: false
12
16
 
13
17
  steps:
14
18
  - name: Checkout spreadbase repository
15
- uses: actions/checkout@v2
19
+ uses: actions/checkout@v4
16
20
 
17
21
  - name: Setup Ruby
18
22
  uses: ruby/setup-ruby@v1
data/Gemfile CHANGED
@@ -1,7 +1,3 @@
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
@@ -33,8 +33,8 @@ module SpreadBase # :nodoc:
33
33
  #
34
34
  # _returns_ the archive as binary string.
35
35
  #
36
- def encode_to_archive(el_document, options={})
37
- document_buffer = encode_to_content_xml(el_document, options)
36
+ def encode_to_archive(el_document, **options)
37
+ document_buffer = encode_to_content_xml(el_document, **options)
38
38
  zip_buffer = ''
39
39
 
40
40
  Zip::File.open_buffer(zip_buffer) do | zip_file |
@@ -58,10 +58,10 @@ module SpreadBase # :nodoc:
58
58
  #
59
59
  # _returns_ the SpreadBase::Document instance.
60
60
  #
61
- def decode_archive(zip_buffer, options={})
61
+ def decode_archive(zip_buffer, **options)
62
62
  content_xml_data = read_content_xml(zip_buffer)
63
63
 
64
- decode_content_xml(content_xml_data, options)
64
+ decode_content_xml(content_xml_data, **options)
65
65
  end
66
66
 
67
67
  # Utility method; encodes the Document to the content.xml format.
@@ -78,7 +78,7 @@ module SpreadBase # :nodoc:
78
78
  #--
79
79
  # "utility" is a fancy name for testing/utils helper.
80
80
  #
81
- def encode_to_content_xml(el_document, options={})
81
+ def encode_to_content_xml(el_document, **options)
82
82
  prettify = options[:prettify]
83
83
 
84
84
  document_xml_root = encode_to_document_node(el_document)
@@ -97,10 +97,10 @@ module SpreadBase # :nodoc:
97
97
  #--
98
98
  # "utility" is a fancy name for testing/utils helper.
99
99
  #
100
- def decode_content_xml(content_xml_data, options={})
100
+ def decode_content_xml(content_xml_data, **options)
101
101
  root_node = REXML::Document.new(content_xml_data)
102
102
 
103
- decode_document_node(root_node, options)
103
+ decode_document_node(root_node, **options)
104
104
  end
105
105
 
106
106
  private
@@ -17,7 +17,7 @@ module SpreadBase # :nodoc:
17
17
 
18
18
  # Returns a Document instance.
19
19
  #
20
- def decode_document_node(root_node, options={})
20
+ def decode_document_node(root_node, **options)
21
21
  document = Document.new
22
22
 
23
23
  style_nodes = root_node.elements.to_a('//office:document-content/office:automatic-styles/style:style')
@@ -25,7 +25,7 @@ module SpreadBase # :nodoc:
25
25
 
26
26
  document.column_width_styles = decode_column_width_styles(style_nodes)
27
27
 
28
- document.tables = table_nodes.map { | node | decode_table_node(node, options) }
28
+ document.tables = table_nodes.map { | node | decode_table_node(node, **options) }
29
29
 
30
30
  document
31
31
  end
@@ -50,7 +50,7 @@ module SpreadBase # :nodoc:
50
50
  end
51
51
  end
52
52
 
53
- def decode_table_node(table_node, options)
53
+ def decode_table_node(table_node, **options)
54
54
  table = Table.new(table_node.attributes['table:name'])
55
55
 
56
56
  column_nodes = table_node.elements.to_a('table:table-column')
@@ -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 = decode_row_nodes(row_nodes, options)
62
+ table.data = decode_row_nodes(row_nodes, **options)
63
63
 
64
64
  table
65
65
  end
@@ -73,21 +73,21 @@ 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)
76
+ def decode_row_nodes(row_nodes, **options)
77
77
  rows = []
78
78
  row_nodes.inject(0) do |size, node|
79
- row, repetitions = decode_row_node(node, options)
79
+ row, repetitions = decode_row_node(node, **options)
80
80
  row.empty? || append_row(rows, size, row, repetitions)
81
81
  size + repetitions
82
82
  end
83
83
  rows
84
84
  end
85
85
 
86
- def decode_row_node(row_node, options)
86
+ def decode_row_node(row_node, **options)
87
87
  repetitions = (row_node.attributes['table:number-rows-repeated'] || '1').to_i
88
88
  cell_nodes = row_node.elements.to_a('table:table-cell')
89
89
 
90
- [decode_cell_nodes(cell_nodes, options), repetitions]
90
+ [decode_cell_nodes(cell_nodes, **options), repetitions]
91
91
  end
92
92
 
93
93
  def append_row(rows, size, row, repetitions)
@@ -95,19 +95,19 @@ module SpreadBase # :nodoc:
95
95
  rows.concat(make_array_from_repetitions(row, repetitions))
96
96
  end
97
97
 
98
- def decode_cell_nodes(cell_nodes, options)
98
+ def decode_cell_nodes(cell_nodes, **options)
99
99
  cells = []
100
100
  cell_nodes.inject(0) do |size, node|
101
- cell, repetitions = decode_cell_node(node, options)
101
+ cell, repetitions = decode_cell_node(node, **options)
102
102
  cell.nil? || append_cell(cells, size, cell, repetitions)
103
103
  size + repetitions
104
104
  end
105
105
  cells
106
106
  end
107
107
 
108
- def decode_cell_node(cell_node, options)
108
+ def decode_cell_node(cell_node, **options)
109
109
  [
110
- decode_cell_value(cell_node, options),
110
+ decode_cell_value(cell_node, **options),
111
111
  (cell_node.attributes['table:number-columns-repeated'] || '1').to_i
112
112
  ]
113
113
  end
@@ -117,7 +117,7 @@ module SpreadBase # :nodoc:
117
117
  cells.concat(make_array_from_repetitions(cell, repetitions))
118
118
  end
119
119
 
120
- def decode_cell_value(cell_node, options)
120
+ def decode_cell_value(cell_node, **options)
121
121
  floats_as_bigdecimal = options[:floats_as_bigdecimal]
122
122
 
123
123
  value_type = cell_node.attributes['office:value-type']
@@ -24,13 +24,13 @@ module SpreadBase # :nodoc:
24
24
  #
25
25
  # +floats_as_bigdecimal+:: (false) decode floats as BigDecimal instead of Float
26
26
  #
27
- def initialize(document_path=nil, options={})
27
+ def initialize(document_path=nil, **options)
28
28
  @document_path = document_path
29
29
  @options = options.clone
30
30
 
31
31
  if @document_path && File.exist?(document_path)
32
32
  document_archive = IO.read(document_path)
33
- decoded_document = Codecs::OpenDocument12.new.decode_archive(document_archive, options)
33
+ decoded_document = Codecs::OpenDocument12.new.decode_archive(document_archive, **options)
34
34
 
35
35
  @column_width_styles = decoded_document.column_width_styles
36
36
  @tables = decoded_document.tables
@@ -48,13 +48,13 @@ module SpreadBase # :nodoc:
48
48
  #
49
49
  # +prettify+:: Prettifies the content.xml file before saving.
50
50
  #
51
- def save(options={})
52
- options = @options.merge(options)
51
+ def save(**options)
52
+ options = @options.merge(**options)
53
53
 
54
54
  raise "At least one table must be present" if @tables.empty?
55
55
  raise "Document path not specified" if @document_path.nil?
56
56
 
57
- document_archive = Codecs::OpenDocument12.new.encode_to_archive(self, options)
57
+ document_archive = Codecs::OpenDocument12.new.encode_to_archive(self, **options)
58
58
 
59
59
  File.open(@document_path, 'wb') { | file | file << document_archive }
60
60
  end
@@ -63,13 +63,13 @@ module SpreadBase # :nodoc:
63
63
  #
64
64
  # +with_headers+:: Print the tables with headers.
65
65
  #
66
- def to_s(options={})
66
+ def to_s(**options)
67
67
  options.merge!(row_prefix: ' ')
68
68
 
69
69
  tables.inject('') do | output, table |
70
70
  output << "#{ table.name }:" << "\n" << "\n"
71
71
 
72
- output << table.to_s(options) << "\n"
72
+ output << table.to_s(**options) << "\n"
73
73
  end
74
74
  end
75
75
 
@@ -34,7 +34,7 @@ module SpreadBase # :nodoc:
34
34
  # +row_prefix+:: Prefix this string to each row.
35
35
  # +with_header+:: First row will be separated from the remaining ones.
36
36
  #
37
- def pretty_print_rows(rows, options={})
37
+ def pretty_print_rows(rows, **options)
38
38
  row_prefix = options[:row_prefix] || ''
39
39
  with_headers = options[:with_headers]
40
40
 
@@ -35,8 +35,8 @@ module SpreadBase # :nodoc:
35
35
  @data = the_data.map { | the_row | array_to_cells(the_row) }
36
36
  end
37
37
 
38
- def data(options={})
39
- @data.map { | the_row | the_row.map { | cell | cell_to_value(cell, options) } }
38
+ def data(**options)
39
+ @data.map { | the_row | the_row.map { | cell | cell_to_value(cell, **options) } }
40
40
  end
41
41
 
42
42
  # Access a cell value.
@@ -48,8 +48,8 @@ module SpreadBase # :nodoc:
48
48
  #
49
49
  # _returns_ the value, which is automatically converted to the Ruby data type.
50
50
  #
51
- def [](column_identifier, row_index, options={})
52
- the_row = row(row_index, options)
51
+ def [](column_identifier, row_index, **options)
52
+ the_row = row(row_index, **options)
53
53
 
54
54
  column_index = decode_column_identifier(column_identifier)
55
55
 
@@ -83,13 +83,13 @@ module SpreadBase # :nodoc:
83
83
  #
84
84
  # +row_index+:: int or range (0-based). see notes about the rows indexing.
85
85
  #
86
- def row(row_index, options={})
86
+ def row(row_index, **options)
87
87
  check_row_index(row_index)
88
88
 
89
89
  if row_index.is_a?(Range)
90
- @data[row_index].map { | row | cells_to_array(row, options) }
90
+ @data[row_index].map { | row | cells_to_array(row, **options) }
91
91
  else
92
- cells_to_array(@data[row_index], options)
92
+ cells_to_array(@data[row_index], **options)
93
93
  end
94
94
  end
95
95
 
@@ -149,7 +149,7 @@ module SpreadBase # :nodoc:
149
149
  # for multiple access, use a range either of int or excel-format identifiers - pay attention, because ( 'A'..'c' ) is not semantically correct.
150
150
  # interestingly, ruby letter ranges convention is the same as the excel columns one.
151
151
  #
152
- def column(column_identifier, options={})
152
+ def column(column_identifier, **options)
153
153
  if column_identifier.is_a?(Range)
154
154
  min_index = decode_column_identifier(column_identifier.min)
155
155
  max_index = decode_column_identifier(column_identifier.max)
@@ -158,7 +158,7 @@ module SpreadBase # :nodoc:
158
158
  @data.map do | the_row |
159
159
  cell = the_row[column_index]
160
160
 
161
- cell_to_value(cell, options)
161
+ cell_to_value(cell, **options)
162
162
  end
163
163
  end
164
164
  else
@@ -167,7 +167,7 @@ module SpreadBase # :nodoc:
167
167
  @data.map do | the_row |
168
168
  cell = the_row[column_index]
169
169
 
170
- cell_to_value(cell, options)
170
+ cell_to_value(cell, **options)
171
171
  end
172
172
  end
173
173
  end
@@ -248,8 +248,8 @@ module SpreadBase # :nodoc:
248
248
 
249
249
  # _returns_ a matrix representation of the tables, with the values being separated by commas.
250
250
  #
251
- def to_s(options={})
252
- pretty_print_rows(data, options)
251
+ def to_s(**options)
252
+ pretty_print_rows(data, **options)
253
253
  end
254
254
 
255
255
  private
@@ -262,11 +262,11 @@ module SpreadBase # :nodoc:
262
262
  value.is_a?(Cell) ? value : Cell.new(value)
263
263
  end
264
264
 
265
- def cells_to_array(cells, options={})
266
- cells.map { | cell | cell_to_value(cell, options) }
265
+ def cells_to_array(cells, **options)
266
+ cells.map { | cell | cell_to_value(cell, **options) }
267
267
  end
268
268
 
269
- def cell_to_value(cell, options={})
269
+ def cell_to_value(cell, **options)
270
270
  as_cell = options[:as_cell]
271
271
 
272
272
  if as_cell
@@ -283,7 +283,7 @@ module SpreadBase # :nodoc:
283
283
  #
284
284
  # +allow_append+:: Allow pointing to one unit above the last row.
285
285
  #
286
- def check_row_index(row_index, options={})
286
+ def check_row_index(row_index, **options)
287
287
  allow_append = options [:allow_append]
288
288
 
289
289
  positive_limit = allow_append ? @data.size : @data.size - 1
@@ -1,3 +1,3 @@
1
1
  module SpreadBase
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -35,7 +35,7 @@ describe SpreadBase::Document do
35
35
 
36
36
  expect(File).to receive(:'exist?').with('/pizza/margerita.txt').and_return(true)
37
37
  expect(IO).to receive(:read).with('/pizza/margerita.txt').and_return('abc')
38
- expect(codec).to receive(:decode_archive).with('abc', {}).and_return(@sample_document)
38
+ expect(codec).to receive(:decode_archive).with('abc').and_return(@sample_document)
39
39
 
40
40
  document = SpreadBase::Document.new('/pizza/margerita.txt')
41
41
 
data/spreadbase.gemspec CHANGED
@@ -8,19 +8,21 @@ Gem::Specification.new do |s|
8
8
  s.name = "spreadbase"
9
9
  s.version = SpreadBase::VERSION
10
10
  s.platform = Gem::Platform::RUBY
11
- s.required_ruby_version = '>= 2.4.0'
11
+ s.required_ruby_version = '>= 3.0.0'
12
12
  s.authors = ["Saverio Miroddi"]
13
- s.date = '2021-12-31'
13
+ s.date = '2024-01-03'
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.}
17
17
  s.description = %q{Library for reading/writing OpenOffice Calc documents.}
18
18
  s.license = "GPL-3.0"
19
19
 
20
- s.add_runtime_dependency "rubyzip", ">=2.3.0"
21
- s.add_development_dependency "rspec", "~>3.9.0"
20
+ s.add_runtime_dependency "rubyzip", ">= 2.3.0"
21
+ s.add_runtime_dependency "bigdecimal", ">= 3.0.0"
22
+ s.add_runtime_dependency "rexml", ">= 3.2.4"
22
23
 
23
- s.add_development_dependency "rake", "~>13.0"
24
+ s.add_development_dependency "rspec", "~> 3.12.0"
25
+ s.add_development_dependency "rake", "~> 13.0"
24
26
 
25
27
  s.files = `git ls-files`.split("\n")
26
28
  s.test_files = `git ls-files -- {spec,temp,utils}/*`.split("\n")
@@ -102,7 +102,7 @@ end
102
102
  # +options+:
103
103
  # +insert_headers+:: (true) insert the column names as headers
104
104
  #
105
- def convert_sqlite_to_ods(source_filename, options={})
105
+ def convert_sqlite_to_ods(source_filename, **options)
106
106
  insert_headers = ! options.has_key?(:insert_headers) || options[:insert_headers]
107
107
 
108
108
  destination_filename = generate_destination_filename(source_filename)
@@ -16,7 +16,7 @@ module UtilsHelpers
16
16
  # :content [nil]
17
17
  # :name_prefix [spreadbase_testing]
18
18
  #
19
- def with_tempfile(options={}, &block)
19
+ def with_tempfile(**options, &block)
20
20
  content = options[:content]
21
21
  name_prefix = options[:name_prefix] || 'spreadbase_testing'
22
22
 
@@ -33,7 +33,7 @@ module UtilsHelpers
33
33
 
34
34
  # Create an archive, whose entries' path is relative to the path passed.
35
35
  #
36
- def relative_compress_to_zip(folder_path, options={})
36
+ def relative_compress_to_zip(folder_path, **options)
37
37
  absolute_path = File.expand_path(folder_path) + '/'
38
38
  zip_filename = options[:zip_filename] || File.expand_path(folder_path) + '.zip'
39
39
 
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.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saverio Miroddi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-31 00:00:00.000000000 Z
11
+ date: 2024-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -24,20 +24,48 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bigdecimal
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rexml
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.4
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.4
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: rspec
29
57
  requirement: !ruby/object:Gem::Requirement
30
58
  requirements:
31
59
  - - "~>"
32
60
  - !ruby/object:Gem::Version
33
- version: 3.9.0
61
+ version: 3.12.0
34
62
  type: :development
35
63
  prerelease: false
36
64
  version_requirements: !ruby/object:Gem::Requirement
37
65
  requirements:
38
66
  - - "~>"
39
67
  - !ruby/object:Gem::Version
40
- version: 3.9.0
68
+ version: 3.12.0
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rake
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -101,14 +129,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
129
  requirements:
102
130
  - - ">="
103
131
  - !ruby/object:Gem::Version
104
- version: 2.4.0
132
+ version: 3.0.0
105
133
  required_rubygems_version: !ruby/object:Gem::Requirement
106
134
  requirements:
107
135
  - - ">="
108
136
  - !ruby/object:Gem::Version
109
137
  version: '0'
110
138
  requirements: []
111
- rubygems_version: 3.2.22
139
+ rubygems_version: 3.4.19
112
140
  signing_key:
113
141
  specification_version: 4
114
142
  summary: Library for reading/writing OpenOffice Calc documents.