spreadbase 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/spreadbase.gemspec CHANGED
@@ -1,6 +1,6 @@
1
- # encoding: UTF-8
1
+ # frozen_string_literal: true
2
2
 
3
- $:.push( File.expand_path( "../lib", __FILE__ ) )
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.authors = [ "Saverio Miroddi" ]
12
- s.email = [ "saverio.pub2@gmail.com" ]
13
- s.homepage = ""
11
+ s.required_ruby_version = '>= 2.3.0'
12
+ s.authors = ["Saverio Miroddi"]
13
+ s.date = '2020-02-03'
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
20
  s.add_runtime_dependency "zipruby", "~>0.3.6"
18
- s.add_development_dependency "rspec", "~>2.9.0"
21
+ s.add_development_dependency "rspec", "~>3.9.0"
19
22
 
20
- s.files = `git ls-files`.split( "\n" )
21
- s.test_files = `git ls-files -- {spec,temp,utils}/*`.split( "\n" )
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 = [ "lib" ]
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 [ '-h', '--help' ].include?( ARGV[ 0 ] ) || ARGV.size == 0 || ARGV.size > 1
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[ 0 ]
13
+ ARGV[0]
33
14
  end
34
15
  end
35
16
 
36
- def generate_destination_filename( source_filename )
17
+ def generate_destination_filename(source_filename)
37
18
  "#{ source_filename }.ods"
38
19
  end
39
20
 
40
- def with_database( filename, &block )
41
- @db = SQLite3::Database.new( filename )
21
+ def with_database(filename, &block)
22
+ @db = SQLite3::Database.new(filename)
42
23
  @db.type_translation = true
43
- @db.extend( SQLite3::Pragmas )
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( filename )
51
- @spreadsheet = SpreadBase::Document.new( filename )
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( sql ).map( &:first ) - [ 'sqlite_sequence' ]
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( table )
80
- raw_data = @db.table_info( table )
60
+ def find_table_columns(table)
61
+ raw_data = @db.table_info(table)
81
62
 
82
- raw_data.map { | column_data | column_data[ 'name' ] }
63
+ raw_data.map { | column_data | column_data['name'] }
83
64
  end
84
65
 
85
- def create_destination_table( table_name, columns )
86
- table = SpreadBase::Table.new( table_name )
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( table )
74
+ def select_all_rows(table)
94
75
  sql = "SELECT * FROM #{ table }"
95
76
 
96
- @db.execute( sql )
77
+ @db.execute(sql)
97
78
  end
98
79
 
99
- def insert_row_into_destination( destination_table, row )
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( 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( source_filename, options={} )
125
- insert_headers = ! options.has_key?( :insert_headers ) || options[ :insert_headers ]
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( source_filename )
108
+ destination_filename = generate_destination_filename(source_filename)
128
109
 
129
- with_database( source_filename ) do
130
- with_spreadsheet( destination_filename ) do
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( table )
115
+ columns = find_table_columns(table)
135
116
 
136
- destination_table = create_destination_table( table, columns )
117
+ destination_table = create_destination_table(table, columns)
137
118
 
138
- insert_row_into_destination( destination_table, columns ) if insert_headers
119
+ insert_row_into_destination(destination_table, columns) if insert_headers
139
120
 
140
- value_rows = select_all_rows( table )
121
+ value_rows = select_all_rows(table)
141
122
 
142
123
  value_rows.each do | row |
143
- insert_row_into_destination( destination_table, row )
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__ == $0
131
+ if __FILE__ == $PROGRAM_NAME
151
132
  filename = decode_cmdline_params
152
133
 
153
- convert_sqlite_to_ods( filename )
134
+ convert_sqlite_to_ods(filename)
154
135
  end
@@ -1,40 +1,21 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
2
 
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
-
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( folder_path )
7
+ def test_ods_folder(folder_path)
27
8
  with_tempfile do | temp_file |
28
- relative_compress_to_zip( folder_path, :zip_filename => temp_file.path )
9
+ relative_compress_to_zip(folder_path, zip_filename: temp_file.path)
29
10
 
30
- `openoffice.org3 #{ temp_file.path }`
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__ == $0
37
- folder_path = ARGV[ 0 ] || raise( "Usage: test_ods_folder.rb <folder>" )
17
+ if __FILE__ == $PROGRAM_NAME
18
+ folder_path = ARGV[0] || raise("Usage: test_ods_folder.rb <folder>")
38
19
 
39
- test_ods_folder( folder_path )
20
+ test_ods_folder(folder_path)
40
21
  end
@@ -1,38 +1,22 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
2
 
4
- =begin
5
- Copyright 2012 Saverio Miroddi saverio.pub2 <a-hat!> gmail.com
3
+ require_relative '../lib/spreadbase'
4
+ require_relative 'utils_helpers'
6
5
 
7
- This file is part of SpreadBase.
6
+ include UtilsHelpers
8
7
 
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.
8
+ def test_recoding_file(file_path)
9
+ destination_file_path = file_path.sub(/\.ods$/, '.2.ods')
13
10
 
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( '../../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( :prettify => true )
13
+ document.save(prettify: true)
30
14
 
31
- `openoffice.org3 #{ destination_file_path }`
15
+ open_office_document(destination_file_path)
32
16
  end
33
17
 
34
- if __FILE__ == $0
35
- file_path = ARGV[ 0 ] || raise( "Usage: test_recoding_file.rb <file>" )
18
+ if __FILE__ == $PROGRAM_NAME
19
+ file_path = ARGV[0] || raise("Usage: test_recoding_file.rb <file>")
36
20
 
37
- test_recoding_file( file_path )
21
+ test_recoding_file(file_path)
38
22
  end
@@ -1,43 +1,24 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
2
 
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
-
22
- require File.expand_path( '../../lib/spreadbase', __FILE__ )
23
- require File.expand_path( '../utils_helpers', __FILE__ )
3
+ require_relative '../lib/spreadbase'
4
+ require_relative 'utils_helpers'
24
5
 
25
6
  include UtilsHelpers
26
7
 
27
- def test_recoding_from_content( file_path )
28
- content_xml_data = IO.read( file_path )
29
- document = SpreadBase::Codecs::OpenDocument12.new.decode_content_xml( content_xml_data )
8
+ def test_recoding_from_content(file_path)
9
+ content_xml_data = IO.read(file_path)
10
+ document = SpreadBase::Codecs::OpenDocument12.new.decode_content_xml(content_xml_data)
30
11
 
31
12
  with_tempfile do | temp_file |
32
13
  document.document_path = temp_file.path
33
- document.save( :prettify => true )
14
+ document.save(prettify: true)
34
15
 
35
- `openoffice.org3 #{ temp_file.path }`
16
+ open_office_document(temp_file.path)
36
17
  end
37
18
  end
38
19
 
39
- if __FILE__ == $0
40
- file_path = ARGV[ 0 ] || raise( "Usage: test_recoding_from_content.rb <file>" )
20
+ if __FILE__ == $PROGRAM_NAME
21
+ file_path = ARGV[0] || raise("Usage: test_recoding_from_content.rb <file>")
41
22
 
42
- test_recoding_from_content( file_path )
23
+ test_recoding_from_content(file_path)
43
24
  end
@@ -1,28 +1,14 @@
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 'tempfile'
22
2
  require 'zipruby'
23
3
 
24
4
  module UtilsHelpers
25
5
 
6
+ # Kept trivial; will extend if needed/useful.
7
+ #
8
+ def open_office_document(file)
9
+ `xdg-open '#{ file }'`
10
+ end
11
+
26
12
  # The file is closed before being passed to the block; even if overwritten, it's deleted when
27
13
  # the object is garbage-collected.
28
14
  #
@@ -30,38 +16,38 @@ module UtilsHelpers
30
16
  # :content [nil]
31
17
  # :name_prefix [spreadbase_testing]
32
18
  #
33
- def with_tempfile( options={}, &block )
34
- content = options[ :content ]
35
- name_prefix = options[ :name_prefix ] || 'spreadbase_testing'
19
+ def with_tempfile(options={}, &block)
20
+ content = options[:content]
21
+ name_prefix = options[:name_prefix] || 'spreadbase_testing'
36
22
 
37
- temp_file = Tempfile.new( name_prefix )
23
+ temp_file = Tempfile.new(name_prefix)
38
24
 
39
25
  temp_file << content if content
40
26
 
41
27
  temp_file.close
42
28
 
43
- yield( temp_file )
29
+ yield(temp_file)
44
30
 
45
31
  temp_file
46
32
  end
47
33
 
48
34
  # Create an archive, whose entries' path is relative to the path passed.
49
35
  #
50
- def relative_compress_to_zip( folder_path, options={} )
51
- absolute_path = File.expand_path( folder_path ) + '/'
52
- zip_filename = options[ :zip_filename ] || File.expand_path( folder_path ) + '.zip'
36
+ def relative_compress_to_zip(folder_path, options={})
37
+ absolute_path = File.expand_path(folder_path) + '/'
38
+ zip_filename = options[:zip_filename] || File.expand_path(folder_path) + '.zip'
53
39
 
54
- absolute_files = Dir.glob( absolute_path + '**/*' )
40
+ absolute_files = Dir.glob(absolute_path + '**/*')
55
41
 
56
- Zip::Archive.open( zip_filename, Zip::CREATE ) do | archive |
42
+ Zip::Archive.open(zip_filename, Zip::CREATE) do | archive |
57
43
  absolute_files.each do | absolute_file |
58
44
  # Lovely ZipRuby
59
45
  #
60
- next if File.directory?( absolute_file )
46
+ next if File.directory?(absolute_file)
61
47
 
62
- relative_file = absolute_file.sub( absolute_path, '' )
48
+ relative_file = absolute_file.sub(absolute_path, '')
63
49
 
64
- archive.add_file( relative_file, absolute_file )
50
+ archive.add_file(relative_file, absolute_file)
65
51
  end
66
52
  end
67
53
  end
metadata CHANGED
@@ -1,48 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spreadbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
5
- prerelease:
4
+ version: 0.1.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Saverio Miroddi
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-05-01 00:00:00.000000000 Z
11
+ date: 2020-02-03 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: zipruby
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: 0.3.6
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: 0.3.6
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
- version: 2.9.0
33
+ version: 3.9.0
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
- version: 2.9.0
40
+ version: 3.9.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
46
55
  description: Library for reading/writing OpenOffice Calc documents.
47
56
  email:
48
57
  - saverio.pub2@gmail.com
@@ -50,10 +59,17 @@ executables: []
50
59
  extensions: []
51
60
  extra_rdoc_files: []
52
61
  files:
53
- - .gitignore
54
- - COPYING.LESSER
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE
55
67
  - README.md
68
+ - Rakefile
69
+ - docs/STRUCTURE.md
70
+ - docs/TESTING.md
56
71
  - lib/spreadbase.rb
72
+ - lib/spreadbase/cell.rb
57
73
  - lib/spreadbase/codecs/open_document_12.rb
58
74
  - lib/spreadbase/codecs/open_document_12_modules/decoding.rb
59
75
  - lib/spreadbase/codecs/open_document_12_modules/encoding.rb
@@ -64,36 +80,35 @@ files:
64
80
  - spec/codecs/open_document_12_spec.rb
65
81
  - spec/elements/document_spec.rb
66
82
  - spec/elements/table_spec.rb
83
+ - spec/spec_helper.rb
67
84
  - spec/spec_helpers.rb
68
85
  - spreadbase.gemspec
69
86
  - utils/convert_sqlite_to_ods.rb
70
- - utils/prettify_file.rb
71
87
  - utils/test_ods_folder.rb
72
88
  - utils/test_recoding_file.rb
73
89
  - utils/test_recoding_from_content.rb
74
90
  - utils/utils_helpers.rb
75
- homepage: ''
76
- licenses: []
91
+ homepage: https://github.com/saveriomiroddi/spreadbase
92
+ licenses:
93
+ - GPL-3.0
94
+ metadata: {}
77
95
  post_install_message:
78
96
  rdoc_options: []
79
97
  require_paths:
80
98
  - lib
81
99
  required_ruby_version: !ruby/object:Gem::Requirement
82
- none: false
83
100
  requirements:
84
- - - ! '>='
101
+ - - ">="
85
102
  - !ruby/object:Gem::Version
86
- version: '0'
103
+ version: 2.3.0
87
104
  required_rubygems_version: !ruby/object:Gem::Requirement
88
- none: false
89
105
  requirements:
90
- - - ! '>='
106
+ - - ">="
91
107
  - !ruby/object:Gem::Version
92
108
  version: '0'
93
109
  requirements: []
94
- rubyforge_project:
95
- rubygems_version: 1.8.23
110
+ rubygems_version: 3.0.6
96
111
  signing_key:
97
- specification_version: 3
112
+ specification_version: 4
98
113
  summary: Library for reading/writing OpenOffice Calc documents.
99
114
  test_files: []