roo-oxide 0.0.2
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +63 -0
- data/Cargo.lock +341 -0
- data/Cargo.toml +7 -0
- data/LICENSE +21 -0
- data/README.md +220 -0
- data/ext/roo_oxide/Cargo.toml +19 -0
- data/ext/roo_oxide/extconf.rb +14 -0
- data/ext/roo_oxide/src/archive.rs +546 -0
- data/ext/roo_oxide/src/convert/cells.rs +516 -0
- data/ext/roo_oxide/src/convert/csv.rs +209 -0
- data/ext/roo_oxide/src/convert.rs +687 -0
- data/ext/roo_oxide/src/lib.rs +306 -0
- data/ext/roo_oxide/src/numeric.rs +174 -0
- data/ext/roo_oxide/src/reader/attributes.rs +199 -0
- data/ext/roo_oxide/src/reader/tests.rs +475 -0
- data/ext/roo_oxide/src/reader.rs +944 -0
- data/ext/roo_oxide/src/shared_strings.rs +684 -0
- data/ext/roo_oxide/src/sheet_parts.rs +312 -0
- data/ext/roo_oxide/src/store/formatters.rs +177 -0
- data/ext/roo_oxide/src/store.rs +894 -0
- data/lib/roo/calamine/version.rb +5 -0
- data/lib/roo/calamine.rb +3 -0
- data/lib/roo/oxide/context.rb +74 -0
- data/lib/roo/oxide/csv.rb +157 -0
- data/lib/roo/oxide/deferred_sheets.rb +284 -0
- data/lib/roo/oxide/excelx.rb +156 -0
- data/lib/roo/oxide/formatters.rb +114 -0
- data/lib/roo/oxide/row_index.rb +93 -0
- data/lib/roo/oxide/row_iteration.rb +33 -0
- data/lib/roo/oxide/shared_strings.rb +46 -0
- data/lib/roo/oxide/sheet.rb +99 -0
- data/lib/roo/oxide/sheet_doc.rb +138 -0
- data/lib/roo/oxide/sheet_parts.rb +78 -0
- data/lib/roo/oxide/version.rb +7 -0
- data/lib/roo/oxide.rb +100 -0
- metadata +110 -0
data/lib/roo/oxide.rb
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "roo"
|
|
4
|
+
require "roo/excelx"
|
|
5
|
+
require_relative "oxide/version"
|
|
6
|
+
|
|
7
|
+
if Roo.const_defined?(:Calamine, false) && !Roo::Calamine.equal?(Roo::Oxide)
|
|
8
|
+
raise LoadError, "Replace roo-calamine with roo-oxide in your Gemfile before loading roo/oxide"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
Roo::Calamine = Roo::Oxide unless Roo.const_defined?(:Calamine, false)
|
|
12
|
+
|
|
13
|
+
module Roo
|
|
14
|
+
# Reads `.xlsx` and `.xlsm` worksheets for Roo::Excelx with a native
|
|
15
|
+
# extension. Loading this file is all it takes; `Roo::Oxide.enabled =
|
|
16
|
+
# false` or `ROO_OXIDE=0` switches back to roo's own reader at runtime.
|
|
17
|
+
module Oxide
|
|
18
|
+
# Raised by the native reader for XML it does not reproduce exactly the
|
|
19
|
+
# way roo reads it. Roo::Oxide rescues it and lets roo read the sheet.
|
|
20
|
+
class UnsupportedError < StandardError; end
|
|
21
|
+
|
|
22
|
+
DISABLING_ENV_VALUES = %w[0 false off].freeze
|
|
23
|
+
private_constant :DISABLING_ENV_VALUES
|
|
24
|
+
|
|
25
|
+
@enabled = true
|
|
26
|
+
|
|
27
|
+
class << self
|
|
28
|
+
attr_writer :enabled
|
|
29
|
+
|
|
30
|
+
# Whether the native extension is loaded. It is `false` on Ruby
|
|
31
|
+
# implementations other than CRuby, such as JRuby.
|
|
32
|
+
def available?
|
|
33
|
+
defined?(Native::Reader) ? true : false
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Whether the next worksheet read goes through the native reader.
|
|
37
|
+
def enabled?
|
|
38
|
+
environment = ENV.fetch("ROO_OXIDE") { ENV.fetch("ROO_CALAMINE", "") }
|
|
39
|
+
@enabled && available? && !DISABLING_ENV_VALUES.include?(environment.downcase)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# roo-oxide's own API, not roo's: yields each row of a worksheet as an
|
|
43
|
+
# Array of the values roo's cells return from `#value`, without building
|
|
44
|
+
# the cells. A row is what
|
|
45
|
+
# `Roo::Excelx#each_row_streaming(sheet:, pad_cells: true)` yields, with
|
|
46
|
+
# `cell&.value` in place of each cell: one entry per column from A up to
|
|
47
|
+
# the row's last cell, `nil` where the worksheet has no cell.
|
|
48
|
+
#
|
|
49
|
+
# `source` and `options` are what `Roo::Excelx.new` takes. The workbook
|
|
50
|
+
# is closed when the block returns. Without a block, returns an
|
|
51
|
+
# Enumerator.
|
|
52
|
+
def each_row_values(source, sheet: nil, **options, &block)
|
|
53
|
+
return enum_for(__method__, source, sheet:, **options) unless block
|
|
54
|
+
|
|
55
|
+
workbook = Roo::Excelx.new(source, options)
|
|
56
|
+
roo_sheet = workbook.sheet_for(sheet)
|
|
57
|
+
if available?
|
|
58
|
+
roo_sheet.instance_variable_get(:@sheet).each_row_values(roo_sheet, &block)
|
|
59
|
+
else
|
|
60
|
+
roo_sheet.each_row(pad_cells: true) { |cells| yield cells.map { |cell| cell&.value } }
|
|
61
|
+
end
|
|
62
|
+
nil
|
|
63
|
+
ensure
|
|
64
|
+
workbook&.close
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
if RUBY_ENGINE == "ruby"
|
|
71
|
+
begin
|
|
72
|
+
require "roo/oxide/#{RUBY_VERSION[/\d+\.\d+/]}/roo_oxide"
|
|
73
|
+
rescue LoadError
|
|
74
|
+
require "roo/oxide/roo_oxide"
|
|
75
|
+
end
|
|
76
|
+
require_relative "oxide/context"
|
|
77
|
+
require_relative "oxide/deferred_sheets"
|
|
78
|
+
require_relative "oxide/sheet_doc"
|
|
79
|
+
require_relative "oxide/sheet_parts"
|
|
80
|
+
require_relative "oxide/excelx"
|
|
81
|
+
require_relative "oxide/csv"
|
|
82
|
+
require_relative "oxide/formatters"
|
|
83
|
+
require_relative "oxide/row_index"
|
|
84
|
+
require_relative "oxide/row_iteration"
|
|
85
|
+
require_relative "oxide/sheet"
|
|
86
|
+
require_relative "oxide/shared_strings"
|
|
87
|
+
Roo::Excelx::SheetDoc.prepend(Roo::Oxide::DeferredSheetDoc)
|
|
88
|
+
Roo::Excelx::SheetDoc.prepend(Roo::Oxide::SheetDoc)
|
|
89
|
+
Roo::Excelx::SheetDoc.prepend(Roo::Oxide::SheetParts)
|
|
90
|
+
Roo::Excelx::Relationships.prepend(Roo::Oxide::HyperlinkRelationships)
|
|
91
|
+
Roo::Excelx::Sheet.prepend(Roo::Oxide::Sheet)
|
|
92
|
+
Roo::Excelx.prepend(Roo::Oxide::DeferredSheets)
|
|
93
|
+
Roo::Excelx.prepend(Roo::Oxide::Excelx)
|
|
94
|
+
Roo::Excelx.prepend(Roo::Oxide::SheetSelection)
|
|
95
|
+
Roo::Excelx::SharedStrings.prepend(Roo::Oxide::SharedStrings)
|
|
96
|
+
Roo::Excelx::Workbook.prepend(Roo::Oxide::MetadataDocument)
|
|
97
|
+
Roo::Excelx::Styles.prepend(Roo::Oxide::MetadataDocument)
|
|
98
|
+
Roo::Excelx.prepend(Roo::Oxide::CSV)
|
|
99
|
+
Roo::Excelx.prepend(Roo::Oxide::Formatters)
|
|
100
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: roo-oxide
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Sebastian Sala
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rb_sys
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 0.9.130
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 0.9.130
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: roo
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '4.0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '4.0'
|
|
40
|
+
description: An unofficial acceleration layer built on top of Roo. Add roo-oxide to
|
|
41
|
+
the Gemfile; Roo is installed as a dependency and its spreadsheet API stays the
|
|
42
|
+
same. A Rust extension speeds up XLSX and XLSM reads while preserving Roo's cell
|
|
43
|
+
and value rules. Unsupported input uses Roo's own reader. Not affiliated with roo-rb.
|
|
44
|
+
executables: []
|
|
45
|
+
extensions:
|
|
46
|
+
- ext/roo_oxide/extconf.rb
|
|
47
|
+
extra_rdoc_files: []
|
|
48
|
+
files:
|
|
49
|
+
- CHANGELOG.md
|
|
50
|
+
- Cargo.lock
|
|
51
|
+
- Cargo.toml
|
|
52
|
+
- LICENSE
|
|
53
|
+
- README.md
|
|
54
|
+
- ext/roo_oxide/Cargo.toml
|
|
55
|
+
- ext/roo_oxide/extconf.rb
|
|
56
|
+
- ext/roo_oxide/src/archive.rs
|
|
57
|
+
- ext/roo_oxide/src/convert.rs
|
|
58
|
+
- ext/roo_oxide/src/convert/cells.rs
|
|
59
|
+
- ext/roo_oxide/src/convert/csv.rs
|
|
60
|
+
- ext/roo_oxide/src/lib.rs
|
|
61
|
+
- ext/roo_oxide/src/numeric.rs
|
|
62
|
+
- ext/roo_oxide/src/reader.rs
|
|
63
|
+
- ext/roo_oxide/src/reader/attributes.rs
|
|
64
|
+
- ext/roo_oxide/src/reader/tests.rs
|
|
65
|
+
- ext/roo_oxide/src/shared_strings.rs
|
|
66
|
+
- ext/roo_oxide/src/sheet_parts.rs
|
|
67
|
+
- ext/roo_oxide/src/store.rs
|
|
68
|
+
- ext/roo_oxide/src/store/formatters.rs
|
|
69
|
+
- lib/roo/calamine.rb
|
|
70
|
+
- lib/roo/calamine/version.rb
|
|
71
|
+
- lib/roo/oxide.rb
|
|
72
|
+
- lib/roo/oxide/context.rb
|
|
73
|
+
- lib/roo/oxide/csv.rb
|
|
74
|
+
- lib/roo/oxide/deferred_sheets.rb
|
|
75
|
+
- lib/roo/oxide/excelx.rb
|
|
76
|
+
- lib/roo/oxide/formatters.rb
|
|
77
|
+
- lib/roo/oxide/row_index.rb
|
|
78
|
+
- lib/roo/oxide/row_iteration.rb
|
|
79
|
+
- lib/roo/oxide/shared_strings.rb
|
|
80
|
+
- lib/roo/oxide/sheet.rb
|
|
81
|
+
- lib/roo/oxide/sheet_doc.rb
|
|
82
|
+
- lib/roo/oxide/sheet_parts.rb
|
|
83
|
+
- lib/roo/oxide/version.rb
|
|
84
|
+
homepage: https://github.com/salasebas/roo-oxide
|
|
85
|
+
licenses:
|
|
86
|
+
- MIT
|
|
87
|
+
metadata:
|
|
88
|
+
homepage_uri: https://github.com/salasebas/roo-oxide
|
|
89
|
+
source_code_uri: https://github.com/salasebas/roo-oxide/tree/v0.0.2
|
|
90
|
+
changelog_uri: https://github.com/salasebas/roo-oxide/blob/v0.0.2/CHANGELOG.md
|
|
91
|
+
bug_tracker_uri: https://github.com/salasebas/roo-oxide/issues
|
|
92
|
+
rubygems_mfa_required: 'true'
|
|
93
|
+
rdoc_options: []
|
|
94
|
+
require_paths:
|
|
95
|
+
- lib
|
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
|
+
requirements:
|
|
98
|
+
- - ">="
|
|
99
|
+
- !ruby/object:Gem::Version
|
|
100
|
+
version: '3.3'
|
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
|
+
requirements:
|
|
103
|
+
- - ">="
|
|
104
|
+
- !ruby/object:Gem::Version
|
|
105
|
+
version: 3.3.11
|
|
106
|
+
requirements: []
|
|
107
|
+
rubygems_version: 3.6.9
|
|
108
|
+
specification_version: 4
|
|
109
|
+
summary: Rust-powered native acceleration for Roo's XLSX and XLSM readers.
|
|
110
|
+
test_files: []
|