ntq_excelsior 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84b27eb6270d0a9527ca77e3c3b9d93328ef2151b14703c796bc07565a16767a
4
- data.tar.gz: ef00357a9c9a2e1c1bc54d6b3ecbe2cc935ce8ba93452acba4d6ecd6a9ed1d94
3
+ metadata.gz: d1f1c651087df6ca7f9dea48884d8976b210294cb95a2577a3048f57ac8488ee
4
+ data.tar.gz: ce39afeae3e37049578a191dea797ce8c7cb06be31c3e60fb726cb823a93140f
5
5
  SHA512:
6
- metadata.gz: 830dd162264d62ac828b52d6dd428f251936b2659fb92e5b34ed3e6809bc84e5b2165c804b637685c1e2a82afcbda86685c9afc663149ce000c103ad0954157f
7
- data.tar.gz: 0baa0a8bc9807bc405d55598d498d731239a1a39823c044784a9ea7c352258ce3b9216d3ded2a329c521a908b0a1ac9f0c7d72bbaa56c09f1ae788e00aca75f5
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
- return {} unless row_styles && row_styles.length > 0
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
- return resolver.call(record) if resolver.is_a?(Proc)
119
-
120
- accessors = resolver
121
- accessors = accessors.split(".") if accessors.is_a?(String)
122
- value = dig_value(record, accessors)
123
- value = value.strftime("%Y-%m-%d") if value.is_a?(Date)
124
- value = value.strftime("%Y-%m-%d %H:%M:%S") if value.is_a?(Time) | value.is_a?(DateTime)
125
- value
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
- row[:values] << format_value(column[:resolve], record)
134
- row[:types] << column[:type] || :string
135
- row[:styles] << get_styles(column[:styles])
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NtqExcelsior
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
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.2.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-03 00:00:00.000000000 Z
11
+ date: 2023-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: caxlsx