ntq_excelsior 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/lib/ntq_excelsior/exporter.rb +34 -16
- data/lib/ntq_excelsior/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1f1c651087df6ca7f9dea48884d8976b210294cb95a2577a3048f57ac8488ee
|
4
|
+
data.tar.gz: ce39afeae3e37049578a191dea797ce8c7cb06be31c3e60fb726cb823a93140f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62c3a791e7fce170b95c2fcd07fa4c9410b57c7aa10570925169cdfa2f38ee603c102a59fafeb49db077ddba9b9644bd6380662105936f12f033c04794d55f33
|
7
|
+
data.tar.gz: c22d31f130c0d0c3ae5f9a52f346255cb0926ad5c56f93880ba12dc8e622260c12a8e35de0eca1bb2d4a58c50bb4fd3d1d2037c53d377fbf3e618b6ed804db24
|
data/README.md
CHANGED
@@ -49,8 +49,7 @@ class UserExporter < NtqExcelsior::Exporter
|
|
49
49
|
},
|
50
50
|
{
|
51
51
|
title: 'Birthdate',
|
52
|
-
resolve: 'birthdate'
|
53
|
-
type: :date
|
52
|
+
resolve: 'birthdate'
|
54
53
|
}
|
55
54
|
{
|
56
55
|
title: 'Address (nested)',
|
@@ -59,6 +58,11 @@ class UserExporter < NtqExcelsior::Exporter
|
|
59
58
|
{
|
60
59
|
title: 'City (nested)',
|
61
60
|
resolve: ['address', 'city']
|
61
|
+
},
|
62
|
+
{
|
63
|
+
title: 'Age',
|
64
|
+
resolve: 'age',
|
65
|
+
type: :number
|
62
66
|
}
|
63
67
|
]
|
64
68
|
})
|
@@ -5,6 +5,12 @@ module NtqExcelsior
|
|
5
5
|
attr_accessor :data
|
6
6
|
|
7
7
|
DEFAULT_STYLES = {
|
8
|
+
date_format: {
|
9
|
+
format_code: 'dd-mm-yyyy'
|
10
|
+
},
|
11
|
+
time_format: {
|
12
|
+
format_code: 'dd-mm-yyyy hh:mm:ss'
|
13
|
+
},
|
8
14
|
bold: {
|
9
15
|
b: true
|
10
16
|
},
|
@@ -73,12 +79,13 @@ module NtqExcelsior
|
|
73
79
|
count
|
74
80
|
end
|
75
81
|
|
76
|
-
def get_styles(row_styles)
|
77
|
-
|
82
|
+
def get_styles(row_styles, cell_styles = [])
|
83
|
+
row_styles ||= []
|
84
|
+
return {} if row_styles.length == 0 && cell_styles.length == 0
|
78
85
|
|
79
86
|
styles_hash = {}
|
80
87
|
stylesheet = styles || {}
|
81
|
-
row_styles.each do |style_key|
|
88
|
+
(row_styles + cell_styles).each do |style_key|
|
82
89
|
styles_hash = styles_hash.merge(stylesheet[style_key] || DEFAULT_STYLES[style_key] || {})
|
83
90
|
end
|
84
91
|
styles_hash
|
@@ -115,14 +122,26 @@ module NtqExcelsior
|
|
115
122
|
end
|
116
123
|
|
117
124
|
def format_value(resolver, record)
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
125
|
+
styles = []
|
126
|
+
type = nil
|
127
|
+
if resolver.is_a?(Proc)
|
128
|
+
value = resolver.call(record)
|
129
|
+
else
|
130
|
+
accessors = resolver
|
131
|
+
accessors = accessors.split(".") if accessors.is_a?(String)
|
132
|
+
value = dig_value(record, accessors)
|
133
|
+
end
|
134
|
+
if value.is_a?(Date)
|
135
|
+
value = value.strftime("%Y-%m-%d")
|
136
|
+
styles << :date_format
|
137
|
+
type = :date
|
138
|
+
end
|
139
|
+
if value.is_a?(Time) | value.is_a?(DateTime)
|
140
|
+
value = value.strftime("%Y-%m-%d %H:%M:%S")
|
141
|
+
styles << :time_format
|
142
|
+
type = :time
|
143
|
+
end
|
144
|
+
{ value: value, styles: styles, type: type }
|
126
145
|
end
|
127
146
|
|
128
147
|
def resolve_record_row(schema, record, index)
|
@@ -130,10 +149,10 @@ module NtqExcelsior
|
|
130
149
|
col_index = 1
|
131
150
|
schema.each do |column|
|
132
151
|
width = column[:width] || 1
|
133
|
-
|
134
|
-
row[:
|
135
|
-
row[:
|
136
|
-
|
152
|
+
formatted_value = format_value(column[:resolve], record)
|
153
|
+
row[:values] << formatted_value[:value]
|
154
|
+
row[:types] << (column[:type] || formatted_value[:type])
|
155
|
+
row[:styles] << get_styles(column[:styles], formatted_value[:styles])
|
137
156
|
if width > 1
|
138
157
|
colspan = width - 1
|
139
158
|
row[:values].push(*Array.new(colspan, nil))
|
@@ -143,7 +162,6 @@ module NtqExcelsior
|
|
143
162
|
|
144
163
|
col_index += 1
|
145
164
|
end
|
146
|
-
|
147
165
|
row
|
148
166
|
end
|
149
167
|
|
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: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: caxlsx
|