ntq_excelsior 1.1.0 → 1.2.1
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 +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +24 -3
- data/lib/ntq_excelsior/exporter.rb +2 -0
- data/lib/ntq_excelsior/importer.rb +5 -1
- data/lib/ntq_excelsior/multi_workbook_exporter.rb +28 -0
- data/lib/ntq_excelsior/version.rb +1 -1
- data/lib/ntq_excelsior.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7623610b856ec03f9eb51aee437b8e7d1357f6cf2a0cf0e28277fe5aca5adb9
|
4
|
+
data.tar.gz: db0984b6a3545570b9d44a24b2e53570b3b2fe15c445488619fee1d9fef07716
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21ea936bacb155d5da8cf1785bb45a3ed2054a871cbcc7797f90ef979954a5e1fb806027527fb130b453cbbee2a32465a4793fb458aa048e280f8ec2e9ce3905
|
7
|
+
data.tar.gz: dcc68660a9802823c1333634fda1d9ca9e41640c3b24af44a1ccb5f08a72f94a79631f435a7a22ac2295d54953686ea26152ac1449f315ea595715a096d74db1
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ntq_excelsior (1.1
|
4
|
+
ntq_excelsior (1.2.1)
|
5
5
|
caxlsx (< 4)
|
6
6
|
roo (< 3)
|
7
7
|
|
@@ -29,7 +29,7 @@ GEM
|
|
29
29
|
rake (13.0.6)
|
30
30
|
regexp_parser (2.8.1)
|
31
31
|
rexml (3.2.5)
|
32
|
-
roo (2.
|
32
|
+
roo (2.8.3)
|
33
33
|
nokogiri (~> 1)
|
34
34
|
rubyzip (>= 1.3.0, < 3.0.0)
|
35
35
|
rspec (3.11.0)
|
@@ -72,4 +72,4 @@ DEPENDENCIES
|
|
72
72
|
rubocop (~> 1.21)
|
73
73
|
|
74
74
|
BUNDLED WITH
|
75
|
-
2.
|
75
|
+
2.3.8
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# NtqExcelsior
|
2
2
|
|
3
|
+
[](https://codeclimate.com/github/9troisquarts/ntq-excelsior/maintainability)
|
4
|
+
|
3
5
|
Ntq excelsior simplifie l'import et l'export de vos données.
|
4
6
|
|
5
7
|
## Installation
|
@@ -79,15 +81,34 @@ exporter.context = { current_user: current_user }
|
|
79
81
|
stream = exporter.export.to_stream.read
|
80
82
|
|
81
83
|
# In ruby file
|
82
|
-
File.open("export.xlsx", "w") do |
|
83
|
-
|
84
|
-
|
84
|
+
File.open("export.xlsx", "w") do |tmp|
|
85
|
+
tmp.binmode
|
86
|
+
tmp.write(stream)
|
85
87
|
end
|
86
88
|
|
87
89
|
# In Controller action
|
88
90
|
send_data stream, type: 'application/xlsx', filename: "filename.xlsx"
|
89
91
|
```
|
90
92
|
|
93
|
+
### Multiple workbooks export
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
user_exporter = UserExporter.new(@user_data)
|
97
|
+
product_exporter = ProductExporter.new(@product_data)
|
98
|
+
|
99
|
+
exporter = NtqExcelsior::MultiWorkbookExporter.new([user_exporter, product_exporter])
|
100
|
+
stream = exporter.export.to_stream.read
|
101
|
+
|
102
|
+
# In ruby file
|
103
|
+
File.open("export.xlsx", "w") do |tmp|
|
104
|
+
tmp.binmode
|
105
|
+
tmp.write(stream)
|
106
|
+
end
|
107
|
+
|
108
|
+
# In Controller action
|
109
|
+
send_data stream, type: 'application/xlsx', filename: "filename.xlsx"
|
110
|
+
```
|
111
|
+
|
91
112
|
### Import
|
92
113
|
|
93
114
|
```ruby
|
@@ -132,6 +132,8 @@ module NtqExcelsior
|
|
132
132
|
v = value
|
133
133
|
return v unless accessors && accessors.length > 0
|
134
134
|
|
135
|
+
return v.dig(*accessors) if v.is_a?(Hash)
|
136
|
+
|
135
137
|
v = v.send(accessors[0])
|
136
138
|
return v if accessors.length == 1
|
137
139
|
return dig_value(v, accessors.slice(1..-1))
|
@@ -76,7 +76,11 @@ module NtqExcelsior
|
|
76
76
|
transform_header_to_regexp(get_column_header(column)) == header_missing_regex
|
77
77
|
end
|
78
78
|
if header_found && header_found.is_a?(Hash)
|
79
|
-
|
79
|
+
if header_found[:header].is_a?(String)
|
80
|
+
missing_headers << header_found[:header]
|
81
|
+
else
|
82
|
+
missing_headers << (header_found[:humanized_header] || header_missing)
|
83
|
+
end
|
80
84
|
elsif header_found&.is_a?(String)
|
81
85
|
missing_headers << header_found
|
82
86
|
else
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'caxlsx'
|
2
|
+
|
3
|
+
module NtqExcelsior
|
4
|
+
class MultiWorkbookExporter
|
5
|
+
|
6
|
+
attr_accessor :exporters
|
7
|
+
|
8
|
+
def initialize(exporters = [])
|
9
|
+
@exporters = exporters
|
10
|
+
end
|
11
|
+
|
12
|
+
def export
|
13
|
+
exports = exporters
|
14
|
+
exports = [exporters] if exporters && !exporters.is_a?(Array)
|
15
|
+
|
16
|
+
package = Axlsx::Package.new
|
17
|
+
wb = package.workbook
|
18
|
+
wb_styles = wb.styles
|
19
|
+
|
20
|
+
exports.each do |exporter|
|
21
|
+
exporter.generate_workbook(wb, wb_styles)
|
22
|
+
end
|
23
|
+
|
24
|
+
package
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
data/lib/ntq_excelsior.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ntq_excelsior
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: caxlsx
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- lib/ntq_excelsior.rb
|
59
59
|
- lib/ntq_excelsior/exporter.rb
|
60
60
|
- lib/ntq_excelsior/importer.rb
|
61
|
+
- lib/ntq_excelsior/multi_workbook_exporter.rb
|
61
62
|
- lib/ntq_excelsior/version.rb
|
62
63
|
- sig/ntq_excelsior.rbs
|
63
64
|
homepage: https://github.com/9troisquarts/ntq-excelsior
|