spreadbase 0.1.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yml +25 -0
- data/.gitignore +3 -2
- data/.rspec +1 -0
- data/Gemfile +7 -0
- data/LICENSE +674 -0
- data/README.md +34 -18
- data/Rakefile +5 -0
- data/docs/STRUCTURE.md +3 -0
- data/docs/TESTING.md +11 -0
- data/lib/spreadbase.rb +7 -28
- data/lib/spreadbase/cell.rb +19 -0
- data/lib/spreadbase/codecs/open_document_12.rb +19 -44
- data/lib/spreadbase/codecs/open_document_12_modules/decoding.rb +99 -94
- data/lib/spreadbase/codecs/open_document_12_modules/encoding.rb +43 -72
- data/lib/spreadbase/document.rb +12 -33
- data/lib/spreadbase/helpers/helpers.rb +27 -61
- data/lib/spreadbase/table.rb +143 -82
- data/lib/spreadbase/version.rb +1 -3
- data/spec/codecs/open_document_12_spec.rb +128 -64
- data/spec/elements/document_spec.rb +56 -55
- data/spec/elements/table_spec.rb +202 -143
- data/spec/fixtures/test.ods +0 -0
- data/spec/spec_helper.rb +100 -0
- data/spec/spec_helpers.rb +10 -30
- data/spreadbase.gemspec +15 -10
- data/utils/convert_sqlite_to_ods.rb +30 -49
- data/utils/test_ods_folder.rb +7 -26
- data/utils/test_recoding_file.rb +11 -27
- data/utils/test_recoding_from_content.rb +10 -29
- data/utils/utils_helpers.rb +19 -33
- metadata +53 -27
- data/COPYING.LESSER +0 -165
- data/utils/prettify_file.rb +0 -46
Binary file
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
6
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
7
|
+
# files.
|
8
|
+
#
|
9
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
10
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
11
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
12
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
13
|
+
# a separate helper file that requires the additional dependencies and performs
|
14
|
+
# the additional setup, and require it from the spec files that actually need
|
15
|
+
# it.
|
16
|
+
#
|
17
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
18
|
+
RSpec.configure do |config|
|
19
|
+
# rspec-expectations config goes here. You can use an alternate
|
20
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
21
|
+
# assertions if you prefer.
|
22
|
+
config.expect_with :rspec do |expectations|
|
23
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
24
|
+
# and `failure_message` of custom matchers include text for helper methods
|
25
|
+
# defined using `chain`, e.g.:
|
26
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
27
|
+
# # => "be bigger than 2 and smaller than 4"
|
28
|
+
# ...rather than:
|
29
|
+
# # => "be bigger than 2"
|
30
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
31
|
+
end
|
32
|
+
|
33
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
34
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
35
|
+
config.mock_with :rspec do |mocks|
|
36
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
37
|
+
# a real object. This is generally recommended, and will default to
|
38
|
+
# `true` in RSpec 4.
|
39
|
+
mocks.verify_partial_doubles = true
|
40
|
+
end
|
41
|
+
|
42
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
43
|
+
# have no way to turn it off -- the option exists only for backwards
|
44
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
45
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
46
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
47
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
48
|
+
|
49
|
+
# The settings below are suggested to provide a good initial experience
|
50
|
+
# with RSpec, but feel free to customize to your heart's content.
|
51
|
+
# This allows you to limit a spec run to individual examples or groups
|
52
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
53
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
54
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
55
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
56
|
+
config.filter_run_when_matching :focus
|
57
|
+
|
58
|
+
# Allows RSpec to persist some state between runs in order to support
|
59
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
60
|
+
# you configure your source control system to ignore this file.
|
61
|
+
# config.example_status_persistence_file_path = "spec/examples.txt"
|
62
|
+
|
63
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
64
|
+
# recommended. For more details, see:
|
65
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
66
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
67
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
68
|
+
# config.disable_monkey_patching!
|
69
|
+
|
70
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
71
|
+
# be too noisy due to issues in dependencies.
|
72
|
+
config.warnings = true
|
73
|
+
|
74
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
75
|
+
# file, and it's useful to allow more verbose output when running an
|
76
|
+
# individual spec file.
|
77
|
+
if config.files_to_run.one?
|
78
|
+
# Use the documentation formatter for detailed output,
|
79
|
+
# unless a formatter has already been configured
|
80
|
+
# (e.g. via a command-line flag).
|
81
|
+
config.default_formatter = "doc"
|
82
|
+
end
|
83
|
+
|
84
|
+
# Print the 10 slowest examples and example groups at the
|
85
|
+
# end of the spec run, to help surface which specs are running
|
86
|
+
# particularly slow.
|
87
|
+
# config.profile_examples = 10
|
88
|
+
|
89
|
+
# Run specs in random order to surface order dependencies. If you find an
|
90
|
+
# order dependency and want to debug it, you can fix the order by providing
|
91
|
+
# the seed, which is printed after each run.
|
92
|
+
# --seed 1234
|
93
|
+
config.order = :random
|
94
|
+
|
95
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
96
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
97
|
+
# test failures related to randomization by passing the same `--seed` value
|
98
|
+
# as the one that triggered the failure.
|
99
|
+
Kernel.srand config.seed
|
100
|
+
end
|
data/spec/spec_helpers.rb
CHANGED
@@ -1,45 +1,25 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
=begin
|
4
|
-
Copyright 2012 Saverio Miroddi saverio.pub2 <a-hat!> gmail.com
|
5
|
-
|
6
|
-
This file is part of SpreadBase.
|
7
|
-
|
8
|
-
SpreadBase is free software: you can redistribute it and/or modify it under the
|
9
|
-
terms of the GNU Lesser General Public License as published by the Free Software
|
10
|
-
Foundation, either version 3 of the License, or (at your option) any later
|
11
|
-
version.
|
12
|
-
|
13
|
-
SpreadBase is distributed in the hope that it will be useful, but WITHOUT ANY
|
14
|
-
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
15
|
-
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
16
|
-
|
17
|
-
You should have received a copy of the GNU Lesser General Public License along
|
18
|
-
with SpreadBase. If not, see <http://www.gnu.org/licenses/>.
|
19
|
-
=end
|
20
|
-
|
21
1
|
require 'date'
|
22
2
|
require 'bigdecimal'
|
23
3
|
|
24
4
|
module SpecHelpers
|
25
5
|
|
26
|
-
T_DATE = Date.new(
|
27
|
-
T_DATETIME = DateTime.new(
|
28
|
-
T_TIME = Time.
|
29
|
-
T_BIGDECIMAL = BigDecimal
|
6
|
+
T_DATE = Date.new(2012, 4, 10)
|
7
|
+
T_DATETIME = DateTime.new(2012, 4, 11, 23, 33, 42)
|
8
|
+
T_TIME = Time.new(2012, 4, 11, 23, 33, 42, "+02:00")
|
9
|
+
T_BIGDECIMAL = BigDecimal('1.33')
|
30
10
|
|
31
11
|
# This method is cool beyond any argument about the imperfect name.
|
32
12
|
#
|
33
|
-
def assert_size(
|
34
|
-
collection.size.
|
13
|
+
def assert_size(collection, expected_size)
|
14
|
+
expect(collection.size).to eql(expected_size)
|
35
15
|
|
36
|
-
yield(
|
16
|
+
yield(*collection) if block_given?
|
37
17
|
end
|
38
18
|
|
39
|
-
def stub_initializer(
|
40
|
-
instance = klazz.new(
|
19
|
+
def stub_initializer(klazz, *args)
|
20
|
+
instance = klazz.new(*args)
|
41
21
|
|
42
|
-
klazz.
|
22
|
+
allow(klazz).to receive(:new) { instance }
|
43
23
|
|
44
24
|
instance
|
45
25
|
end
|
data/spreadbase.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
$LOAD_PATH.push(File.expand_path("../lib", __FILE__))
|
4
4
|
|
5
5
|
require "spreadbase/version"
|
6
6
|
|
@@ -8,17 +8,22 @@ 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.
|
12
|
-
s.
|
13
|
-
s.
|
11
|
+
s.required_ruby_version = '>= 2.4.0'
|
12
|
+
s.authors = ["Saverio Miroddi"]
|
13
|
+
s.date = '2021-03-05'
|
14
|
+
s.email = ["saverio.pub2@gmail.com"]
|
15
|
+
s.homepage = "https://github.com/saveriomiroddi/spreadbase"
|
14
16
|
s.summary = %q{Library for reading/writing OpenOffice Calc documents.}
|
15
17
|
s.description = %q{Library for reading/writing OpenOffice Calc documents.}
|
18
|
+
s.license = "GPL-3.0"
|
16
19
|
|
17
|
-
s.add_runtime_dependency "
|
18
|
-
s.add_development_dependency "rspec", "~>
|
20
|
+
s.add_runtime_dependency "rubyzip", "~>2.3.0"
|
21
|
+
s.add_development_dependency "rspec", "~>3.9.0"
|
19
22
|
|
20
|
-
s.
|
21
|
-
|
23
|
+
s.add_development_dependency "rake", "~>13.0"
|
24
|
+
|
25
|
+
s.files = `git ls-files`.split("\n")
|
26
|
+
s.test_files = `git ls-files -- {spec,temp,utils}/*`.split("\n")
|
22
27
|
s.executables = []
|
23
|
-
s.require_paths = [
|
28
|
+
s.require_paths = ["lib"]
|
24
29
|
end
|
@@ -1,54 +1,35 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
=begin
|
5
|
-
Copyright 2012 Saverio Miroddi saverio.pub2 <a-hat!> gmail.com
|
6
|
-
|
7
|
-
This file is part of SpreadBase.
|
8
|
-
|
9
|
-
SpreadBase is free software: you can redistribute it and/or modify it under the
|
10
|
-
terms of the GNU Lesser General Public License as published by the Free Software
|
11
|
-
Foundation, either version 3 of the License, or (at your option) any later
|
12
|
-
version.
|
13
|
-
|
14
|
-
SpreadBase is distributed in the hope that it will be useful, but WITHOUT ANY
|
15
|
-
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
16
|
-
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
17
|
-
|
18
|
-
You should have received a copy of the GNU Lesser General Public License along
|
19
|
-
with SpreadBase. If not, see <http://www.gnu.org/licenses/>.
|
20
|
-
=end
|
21
2
|
|
22
3
|
require 'rubygems'
|
23
4
|
require 'sqlite3'
|
24
5
|
require 'spreadbase'
|
25
6
|
|
26
7
|
def decode_cmdline_params
|
27
|
-
if [
|
8
|
+
if ['-h', '--help'].include?(ARGV[0]) || ARGV.size == 0 || ARGV.size > 1
|
28
9
|
puts "Usage: convert_sqlite_to_ods.rb <filename>"
|
29
10
|
|
30
11
|
exit
|
31
12
|
else
|
32
|
-
ARGV[
|
13
|
+
ARGV[0]
|
33
14
|
end
|
34
15
|
end
|
35
16
|
|
36
|
-
def generate_destination_filename(
|
17
|
+
def generate_destination_filename(source_filename)
|
37
18
|
"#{ source_filename }.ods"
|
38
19
|
end
|
39
20
|
|
40
|
-
def with_database(
|
41
|
-
@db = SQLite3::Database.new(
|
21
|
+
def with_database(filename, &block)
|
22
|
+
@db = SQLite3::Database.new(filename)
|
42
23
|
@db.type_translation = true
|
43
|
-
@db.extend(
|
24
|
+
@db.extend(SQLite3::Pragmas)
|
44
25
|
|
45
26
|
yield
|
46
27
|
ensure
|
47
28
|
@db.close if @db
|
48
29
|
end
|
49
30
|
|
50
|
-
def with_spreadsheet(
|
51
|
-
@spreadsheet = SpreadBase::Document.new(
|
31
|
+
def with_spreadsheet(filename)
|
32
|
+
@spreadsheet = SpreadBase::Document.new(filename)
|
52
33
|
|
53
34
|
yield
|
54
35
|
ensure
|
@@ -62,7 +43,7 @@ def find_tables
|
|
62
43
|
WHERE type = 'table'
|
63
44
|
"
|
64
45
|
|
65
|
-
@db.execute(
|
46
|
+
@db.execute(sql).map(&:first) - ['sqlite_sequence']
|
66
47
|
end
|
67
48
|
|
68
49
|
# Sample:
|
@@ -76,27 +57,27 @@ end
|
|
76
57
|
# "pk" => 0
|
77
58
|
# },
|
78
59
|
#
|
79
|
-
def find_table_columns(
|
80
|
-
raw_data = @db.table_info(
|
60
|
+
def find_table_columns(table)
|
61
|
+
raw_data = @db.table_info(table)
|
81
62
|
|
82
|
-
raw_data.map { | column_data | column_data[
|
63
|
+
raw_data.map { | column_data | column_data['name'] }
|
83
64
|
end
|
84
65
|
|
85
|
-
def create_destination_table(
|
86
|
-
table = SpreadBase::Table.new(
|
66
|
+
def create_destination_table(table_name, columns)
|
67
|
+
table = SpreadBase::Table.new(table_name)
|
87
68
|
|
88
69
|
@spreadsheet.tables << table
|
89
70
|
|
90
71
|
table
|
91
72
|
end
|
92
73
|
|
93
|
-
def select_all_rows(
|
74
|
+
def select_all_rows(table)
|
94
75
|
sql = "SELECT * FROM #{ table }"
|
95
76
|
|
96
|
-
@db.execute(
|
77
|
+
@db.execute(sql)
|
97
78
|
end
|
98
79
|
|
99
|
-
def insert_row_into_destination(
|
80
|
+
def insert_row_into_destination(destination_table, row)
|
100
81
|
# row = row.map do | value |
|
101
82
|
# if value.is_a?( String )
|
102
83
|
# begin
|
@@ -115,40 +96,40 @@ def insert_row_into_destination( destination_table, row )
|
|
115
96
|
|
116
97
|
# holy crap it's really easy to work with SB. kudos to myself.
|
117
98
|
#
|
118
|
-
destination_table.append_row(
|
99
|
+
destination_table.append_row(row)
|
119
100
|
end
|
120
101
|
|
121
102
|
# +options+:
|
122
103
|
# +insert_headers+:: (true) insert the column names as headers
|
123
104
|
#
|
124
|
-
def convert_sqlite_to_ods(
|
125
|
-
insert_headers = ! options.has_key?(
|
105
|
+
def convert_sqlite_to_ods(source_filename, options={})
|
106
|
+
insert_headers = ! options.has_key?(:insert_headers) || options[:insert_headers]
|
126
107
|
|
127
|
-
destination_filename = generate_destination_filename(
|
108
|
+
destination_filename = generate_destination_filename(source_filename)
|
128
109
|
|
129
|
-
with_database(
|
130
|
-
with_spreadsheet(
|
110
|
+
with_database(source_filename) do
|
111
|
+
with_spreadsheet(destination_filename) do
|
131
112
|
tables = find_tables
|
132
113
|
|
133
114
|
tables.each do | table |
|
134
|
-
columns = find_table_columns(
|
115
|
+
columns = find_table_columns(table)
|
135
116
|
|
136
|
-
destination_table = create_destination_table(
|
117
|
+
destination_table = create_destination_table(table, columns)
|
137
118
|
|
138
|
-
insert_row_into_destination(
|
119
|
+
insert_row_into_destination(destination_table, columns) if insert_headers
|
139
120
|
|
140
|
-
value_rows = select_all_rows(
|
121
|
+
value_rows = select_all_rows(table)
|
141
122
|
|
142
123
|
value_rows.each do | row |
|
143
|
-
insert_row_into_destination(
|
124
|
+
insert_row_into_destination(destination_table, row)
|
144
125
|
end
|
145
126
|
end
|
146
127
|
end
|
147
128
|
end
|
148
129
|
end
|
149
130
|
|
150
|
-
if __FILE__ == $
|
131
|
+
if __FILE__ == $PROGRAM_NAME
|
151
132
|
filename = decode_cmdline_params
|
152
133
|
|
153
|
-
convert_sqlite_to_ods(
|
134
|
+
convert_sqlite_to_ods(filename)
|
154
135
|
end
|
data/utils/test_ods_folder.rb
CHANGED
@@ -1,40 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
2
|
|
4
|
-
|
5
|
-
Copyright 2012 Saverio Miroddi saverio.pub2 <a-hat!> gmail.com
|
6
|
-
|
7
|
-
This file is part of SpreadBase.
|
8
|
-
|
9
|
-
SpreadBase is free software: you can redistribute it and/or modify it under the
|
10
|
-
terms of the GNU Lesser General Public License as published by the Free Software
|
11
|
-
Foundation, either version 3 of the License, or (at your option) any later
|
12
|
-
version.
|
13
|
-
|
14
|
-
SpreadBase is distributed in the hope that it will be useful, but WITHOUT ANY
|
15
|
-
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
16
|
-
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
17
|
-
|
18
|
-
You should have received a copy of the GNU Lesser General Public License along
|
19
|
-
with SpreadBase. If not, see <http://www.gnu.org/licenses/>.
|
20
|
-
=end
|
21
|
-
|
22
|
-
require File.expand_path( '../utils_helpers', __FILE__ )
|
3
|
+
require File.expand_path('../utils_helpers', File.realpath(__FILE__))
|
23
4
|
|
24
5
|
include UtilsHelpers
|
25
6
|
|
26
|
-
def test_ods_folder(
|
7
|
+
def test_ods_folder(folder_path)
|
27
8
|
with_tempfile do | temp_file |
|
28
|
-
relative_compress_to_zip(
|
9
|
+
relative_compress_to_zip(folder_path, zip_filename: temp_file.path)
|
29
10
|
|
30
|
-
|
11
|
+
open_office_document(temp_file.path)
|
31
12
|
end
|
32
13
|
end
|
33
14
|
|
34
15
|
# Not sure if 'folder' is an accepted name in the linux world.
|
35
16
|
#
|
36
|
-
if __FILE__ == $
|
37
|
-
folder_path = ARGV[
|
17
|
+
if __FILE__ == $PROGRAM_NAME
|
18
|
+
folder_path = ARGV[0] || raise("Usage: test_ods_folder.rb <folder>")
|
38
19
|
|
39
|
-
test_ods_folder(
|
20
|
+
test_ods_folder(folder_path)
|
40
21
|
end
|
data/utils/test_recoding_file.rb
CHANGED
@@ -1,38 +1,22 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
2
|
|
4
|
-
|
5
|
-
|
3
|
+
require_relative '../lib/spreadbase'
|
4
|
+
require_relative 'utils_helpers'
|
6
5
|
|
7
|
-
|
6
|
+
include UtilsHelpers
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
Foundation, either version 3 of the License, or (at your option) any later
|
12
|
-
version.
|
8
|
+
def test_recoding_file(file_path)
|
9
|
+
destination_file_path = file_path.sub(/\.ods$/, '.2.ods')
|
13
10
|
|
14
|
-
|
15
|
-
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
16
|
-
PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
17
|
-
|
18
|
-
You should have received a copy of the GNU Lesser General Public License along
|
19
|
-
with SpreadBase. If not, see <http://www.gnu.org/licenses/>.
|
20
|
-
=end
|
21
|
-
|
22
|
-
require File.expand_path( '../../lib/spreadbase', __FILE__ )
|
23
|
-
|
24
|
-
def test_recoding_file( file_path )
|
25
|
-
destination_file_path = file_path.sub( /\.ods$/, '.2.ods' )
|
26
|
-
|
27
|
-
document = SpreadBase::Document.new( file_path )
|
11
|
+
document = SpreadBase::Document.new(file_path)
|
28
12
|
document.document_path = destination_file_path
|
29
|
-
document.save(
|
13
|
+
document.save(prettify: true)
|
30
14
|
|
31
|
-
|
15
|
+
open_office_document(destination_file_path)
|
32
16
|
end
|
33
17
|
|
34
|
-
if __FILE__ == $
|
35
|
-
file_path = ARGV[
|
18
|
+
if __FILE__ == $PROGRAM_NAME
|
19
|
+
file_path = ARGV[0] || raise("Usage: test_recoding_file.rb <file>")
|
36
20
|
|
37
|
-
test_recoding_file(
|
21
|
+
test_recoding_file(file_path)
|
38
22
|
end
|