oxcel 0.1.0
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 +16 -0
- data/Cargo.lock +829 -0
- data/Cargo.toml +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +212 -0
- data/docs/MIGRATING_FROM_CAXLSX.md +120 -0
- data/docs/MIGRATING_FROM_ROO.md +99 -0
- data/ext/oxcel/Cargo.toml +15 -0
- data/ext/oxcel/extconf.rb +8 -0
- data/ext/oxcel/src/error.rs +20 -0
- data/ext/oxcel/src/format.rs +200 -0
- data/ext/oxcel/src/lib.rs +65 -0
- data/ext/oxcel/src/reader.rs +524 -0
- data/ext/oxcel/src/writer.rs +801 -0
- data/lib/oxcel/a1.rb +66 -0
- data/lib/oxcel/compat/caxlsx.rb +295 -0
- data/lib/oxcel/compat/roo.rb +294 -0
- data/lib/oxcel/configuration.rb +29 -0
- data/lib/oxcel/diff.rb +235 -0
- data/lib/oxcel/rails.rb +57 -0
- data/lib/oxcel/reader.rb +135 -0
- data/lib/oxcel/resource.rb +317 -0
- data/lib/oxcel/sheet.rb +188 -0
- data/lib/oxcel/types.rb +130 -0
- data/lib/oxcel/version.rb +5 -0
- data/lib/oxcel/workbook.rb +50 -0
- data/lib/oxcel.rb +169 -0
- data/rbi/oxcel.rbi +1144 -0
- data/sig/oxcel.rbs +404 -0
- data/skills/oxcel/SKILL.md +152 -0
- metadata +89 -0
data/lib/oxcel.rb
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "date"
|
|
4
|
+
require_relative "oxcel/version"
|
|
5
|
+
|
|
6
|
+
begin
|
|
7
|
+
RUBY_VERSION =~ /(\d+\.\d+)/
|
|
8
|
+
require_relative "oxcel/#{Regexp.last_match(1)}/oxcel"
|
|
9
|
+
rescue LoadError
|
|
10
|
+
require_relative "oxcel/oxcel"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
require_relative "oxcel/configuration"
|
|
14
|
+
require_relative "oxcel/a1"
|
|
15
|
+
require_relative "oxcel/types"
|
|
16
|
+
require_relative "oxcel/reader"
|
|
17
|
+
require_relative "oxcel/sheet"
|
|
18
|
+
require_relative "oxcel/workbook"
|
|
19
|
+
require_relative "oxcel/resource"
|
|
20
|
+
|
|
21
|
+
module Oxcel
|
|
22
|
+
private_constant :NativeReader, :NativeWriter
|
|
23
|
+
|
|
24
|
+
autoload :Diff, File.expand_path("oxcel/diff", __dir__)
|
|
25
|
+
autoload :CellDiff, File.expand_path("oxcel/diff", __dir__)
|
|
26
|
+
autoload :DiffResult, File.expand_path("oxcel/diff", __dir__)
|
|
27
|
+
|
|
28
|
+
module Compat
|
|
29
|
+
autoload :Roo, File.expand_path("oxcel/compat/roo", __dir__)
|
|
30
|
+
autoload :Caxlsx, File.expand_path("oxcel/compat/caxlsx", __dir__)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class << self
|
|
34
|
+
def config
|
|
35
|
+
@config ||= Configuration.new
|
|
36
|
+
end
|
|
37
|
+
alias configuration config
|
|
38
|
+
|
|
39
|
+
def configure
|
|
40
|
+
yield config if block_given?
|
|
41
|
+
config
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def reset_config!
|
|
45
|
+
@config = Configuration.new
|
|
46
|
+
end
|
|
47
|
+
alias reset_configuration! reset_config!
|
|
48
|
+
|
|
49
|
+
def open(path_or_io, format: nil)
|
|
50
|
+
reader = Reader.new(path_or_io, format: format)
|
|
51
|
+
return reader unless block_given?
|
|
52
|
+
|
|
53
|
+
begin
|
|
54
|
+
yield reader
|
|
55
|
+
ensure
|
|
56
|
+
reader.close
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def open_bytes(bytes, format: nil)
|
|
61
|
+
reader = Reader.from_bytes(bytes, format: format)
|
|
62
|
+
return reader unless block_given?
|
|
63
|
+
|
|
64
|
+
begin
|
|
65
|
+
yield reader
|
|
66
|
+
ensure
|
|
67
|
+
reader.close
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def sheet_names(path_or_io, format: nil)
|
|
72
|
+
open(path_or_io, format: format, &:sheet_names)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def read(path_or_io, sheet: nil, format: nil, coerce_integers: nil)
|
|
76
|
+
open(path_or_io, format: format) { |r| r.read(sheet, coerce_integers: coerce_integers) }
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def each_row(path_or_io, sheet: nil, format: nil, coerce_integers: nil, skip_empty: false, &block)
|
|
80
|
+
if block_given?
|
|
81
|
+
open(path_or_io, format: format) do |r|
|
|
82
|
+
r.each_row(sheet, coerce_integers: coerce_integers, skip_empty: skip_empty, &block)
|
|
83
|
+
end
|
|
84
|
+
else
|
|
85
|
+
Reader.new(path_or_io, format: format).each_row(
|
|
86
|
+
sheet,
|
|
87
|
+
coerce_integers: coerce_integers,
|
|
88
|
+
skip_empty: skip_empty
|
|
89
|
+
)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def each_hash(path_or_io, sheet: nil, format: nil, headers: nil, coerce_integers: nil, symbolize_keys: false, skip_empty: true, &block)
|
|
94
|
+
if block_given?
|
|
95
|
+
open(path_or_io, format: format) do |r|
|
|
96
|
+
r.each_hash(
|
|
97
|
+
sheet,
|
|
98
|
+
headers: headers,
|
|
99
|
+
coerce_integers: coerce_integers,
|
|
100
|
+
symbolize_keys: symbolize_keys,
|
|
101
|
+
skip_empty: skip_empty,
|
|
102
|
+
&block
|
|
103
|
+
)
|
|
104
|
+
end
|
|
105
|
+
else
|
|
106
|
+
Reader.new(path_or_io, format: format).each_hash(
|
|
107
|
+
sheet,
|
|
108
|
+
headers: headers,
|
|
109
|
+
coerce_integers: coerce_integers,
|
|
110
|
+
symbolize_keys: symbolize_keys,
|
|
111
|
+
skip_empty: skip_empty
|
|
112
|
+
)
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def write(path, constant_memory: nil)
|
|
117
|
+
wb = Workbook.new(constant_memory: constant_memory)
|
|
118
|
+
yield wb if block_given?
|
|
119
|
+
wb.save(path)
|
|
120
|
+
path
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def to_bytes(constant_memory: nil)
|
|
124
|
+
wb = Workbook.new(constant_memory: constant_memory)
|
|
125
|
+
yield wb if block_given?
|
|
126
|
+
wb.to_bytes
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def formula(expression)
|
|
130
|
+
Formula.new(expression)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def link(url, text = nil)
|
|
134
|
+
Hyperlink.new(url, text)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def cell(value, style: nil)
|
|
138
|
+
Cell.new(value, style: style)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def diff(
|
|
142
|
+
left,
|
|
143
|
+
right,
|
|
144
|
+
sheets: nil,
|
|
145
|
+
format_left: nil,
|
|
146
|
+
format_right: nil,
|
|
147
|
+
tolerance: 0.0,
|
|
148
|
+
ignore_trailing_nils: true,
|
|
149
|
+
coerce_integers: true,
|
|
150
|
+
max_diffs: 100
|
|
151
|
+
)
|
|
152
|
+
Diff.compare(
|
|
153
|
+
left,
|
|
154
|
+
right,
|
|
155
|
+
sheets: sheets,
|
|
156
|
+
format_left: format_left,
|
|
157
|
+
format_right: format_right,
|
|
158
|
+
tolerance: tolerance,
|
|
159
|
+
ignore_trailing_nils: ignore_trailing_nils,
|
|
160
|
+
coerce_integers: coerce_integers,
|
|
161
|
+
max_diffs: max_diffs
|
|
162
|
+
)
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# Zero-config Rails integration (amatsuda / Kaminari / jb style):
|
|
168
|
+
# Automatically registers the Railtie when Rails is present; zero overhead outside Rails.
|
|
169
|
+
require_relative "oxcel/rails" if defined?(::Rails::Railtie)
|