eitil 2.0.6 → 2.0.7
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/README.md +0 -1
- data/lib/eitil/all.rb +0 -1
- data/lib/eitil/railtie.rb +1 -1
- data/lib/eitil/version.rb +1 -1
- data/spec/spec_helper.rb +0 -2
- metadata +2 -25
- data/eitil_integrate/README.md +0 -19
- data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/drop_data.rb +0 -63
- data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/format_data.rb +0 -30
- data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/initialize.rb +0 -22
- data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/present_data.rb +0 -31
- data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/reduce_data.rb +0 -18
- data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/sum_data.rb +0 -84
- data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum.rb +0 -10
- data/eitil_integrate/lib/eitil_integrate/application_exporter/default_export.rb +0 -44
- data/eitil_integrate/lib/eitil_integrate/application_exporter/helpers.rb +0 -50
- data/eitil_integrate/lib/eitil_integrate/application_exporter/infos.rb +0 -20
- data/eitil_integrate/lib/eitil_integrate/application_exporter/initialize.rb +0 -32
- data/eitil_integrate/lib/eitil_integrate/application_exporter/log_state.rb +0 -81
- data/eitil_integrate/lib/eitil_integrate/application_exporter/selectors.rb +0 -58
- data/eitil_integrate/lib/eitil_integrate/application_exporter/setters.rb +0 -27
- data/eitil_integrate/lib/eitil_integrate/application_exporter/store_file.rb +0 -50
- data/eitil_integrate/lib/eitil_integrate/application_exporter/style_cells.rb +0 -104
- data/eitil_integrate/lib/eitil_integrate/application_exporter/validations.rb +0 -28
- data/eitil_integrate/lib/eitil_integrate/application_exporter/write_cells.rb +0 -78
- data/eitil_integrate/lib/eitil_integrate/application_exporter/write_messages.rb +0 -18
- data/eitil_integrate/lib/eitil_integrate/application_exporter.rb +0 -22
- data/eitil_integrate/lib/eitil_integrate/railtie.rb +0 -7
- data/eitil_integrate/lib/eitil_integrate.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4beb8f9bfd939bb2015a9e742271f2f7df0ae8c69a640f243635ff2ad7f25fc9
|
4
|
+
data.tar.gz: 61c9cd613c6a365d62e75c768c6293534ce30deba2f4099d7b003f0d5c97991d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9168dbc018c1f5a50fa3130fe44e8f9c13f2fd235c2148bdfce526439abf1a0e4d70688fbc040d6c5f72207559343b8f5e0f10f4c118cb930d2f27a1f5a4b76a
|
7
|
+
data.tar.gz: 945012264b1d857dfea4f1fc5a923da2d1239f57b4a915700ebfd917f389a6dba7481ba80c8088601927f9361a0bdb3a2a6f1f14300a2a8ee0ab9a59d75f10dc
|
data/README.md
CHANGED
@@ -13,7 +13,6 @@ Our gem currently exists of five seperate layers (Railties), which can be integr
|
|
13
13
|
- EitilCore, [docs](/eitil_core) > extends the core classes of Ruby and rails.
|
14
14
|
- EitilSupport, [docs](/eitil_support) > provides utility through stand-alone classes and modules.
|
15
15
|
- EitilStore, [docs](/eitil_store) > stores data in containers, such as Regexp instances.
|
16
|
-
- EitilIntegrate, [docs](/eitil_integrate) > provides seamless integrations with select gems and API's, through helper methods stored in PORO's.
|
17
16
|
|
18
17
|
|
19
18
|
|
data/lib/eitil/all.rb
CHANGED
data/lib/eitil/railtie.rb
CHANGED
data/lib/eitil/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -7,12 +7,10 @@ require 'eitil'
|
|
7
7
|
# Eventually implement specs for all layers.
|
8
8
|
|
9
9
|
require "eitil_core/railtie"
|
10
|
-
require "eitil_integrate/railtie"
|
11
10
|
# require "eitil_store/railtie"
|
12
11
|
# require "eitil_support/railtie"
|
13
12
|
|
14
13
|
require "eitil_core"
|
15
|
-
require "eitil_integrate"
|
16
14
|
# require "eitil_store"
|
17
15
|
# require "eitil_support"
|
18
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eitil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jurriaan Schrofer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -231,29 +231,6 @@ files:
|
|
231
231
|
- eitil_core/lib/eitil_core/type_checkers/is_num_or_nan.rb
|
232
232
|
- eitil_core/lib/eitil_core/validations.rb
|
233
233
|
- eitil_core/lib/eitil_core/validations/run_validations.rb
|
234
|
-
- eitil_integrate/README.md
|
235
|
-
- eitil_integrate/lib/eitil_integrate.rb
|
236
|
-
- eitil_integrate/lib/eitil_integrate/application_exporter.rb
|
237
|
-
- eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum.rb
|
238
|
-
- eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/drop_data.rb
|
239
|
-
- eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/format_data.rb
|
240
|
-
- eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/initialize.rb
|
241
|
-
- eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/present_data.rb
|
242
|
-
- eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/reduce_data.rb
|
243
|
-
- eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/sum_data.rb
|
244
|
-
- eitil_integrate/lib/eitil_integrate/application_exporter/default_export.rb
|
245
|
-
- eitil_integrate/lib/eitil_integrate/application_exporter/helpers.rb
|
246
|
-
- eitil_integrate/lib/eitil_integrate/application_exporter/infos.rb
|
247
|
-
- eitil_integrate/lib/eitil_integrate/application_exporter/initialize.rb
|
248
|
-
- eitil_integrate/lib/eitil_integrate/application_exporter/log_state.rb
|
249
|
-
- eitil_integrate/lib/eitil_integrate/application_exporter/selectors.rb
|
250
|
-
- eitil_integrate/lib/eitil_integrate/application_exporter/setters.rb
|
251
|
-
- eitil_integrate/lib/eitil_integrate/application_exporter/store_file.rb
|
252
|
-
- eitil_integrate/lib/eitil_integrate/application_exporter/style_cells.rb
|
253
|
-
- eitil_integrate/lib/eitil_integrate/application_exporter/validations.rb
|
254
|
-
- eitil_integrate/lib/eitil_integrate/application_exporter/write_cells.rb
|
255
|
-
- eitil_integrate/lib/eitil_integrate/application_exporter/write_messages.rb
|
256
|
-
- eitil_integrate/lib/eitil_integrate/railtie.rb
|
257
234
|
- eitil_store/README.md
|
258
235
|
- eitil_store/lib/eitil_store.rb
|
259
236
|
- eitil_store/lib/eitil_store/array.rb
|
data/eitil_integrate/README.md
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
# EitilIntegrate
|
5
|
-
|
6
|
-
EitilIntegrate provides seamless integrations with select gems and API's, through helper methods stored in PORO's.
|
7
|
-
|
8
|
-
|
9
|
-
## EitilIntegrate::RubyXL::ApplicationExporter
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
|
13
|
-
require "eitil_integrate/application_exporter"
|
14
|
-
|
15
|
-
```
|
16
|
-
|
17
|
-
EitilIntegrate::RubyXL::ApplicationExporter provides an extensive wrapper around the RubyXL gem, and can be used by setting it as the superclass of your application's exporter classes.
|
18
|
-
|
19
|
-
Since the functionality is diverse and changing, you can best look at the source code files for the options and methods.
|
@@ -1,63 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_integrate/application_exporter/auto_sum/drop_data"
|
3
|
-
|
4
|
-
module EitilIntegrate::RubyXL
|
5
|
-
module AutoSum
|
6
|
-
class << self
|
7
|
-
|
8
|
-
def drop_data
|
9
|
-
# since excel layout consistency requires stringified values, we first need
|
10
|
-
# to convert strings back to floats.
|
11
|
-
try_float_conversion
|
12
|
-
|
13
|
-
# after the required conversions, drop all values that should not be accepted.
|
14
|
-
drop_nil_values
|
15
|
-
drop_empty_values
|
16
|
-
drop_non_accepted_values
|
17
|
-
end
|
18
|
-
|
19
|
-
def try_float_conversion
|
20
|
-
@hash.transform_values! { |array| array.map { |item| item.is_num? ? to_float(item) : item } }
|
21
|
-
end
|
22
|
-
|
23
|
-
def drop_nil_values
|
24
|
-
@hash.transform_values! &:compact
|
25
|
-
end
|
26
|
-
|
27
|
-
def drop_empty_values
|
28
|
-
@hash.transform_values! do |array|
|
29
|
-
array.reject { |item| item.respond_to?(:empty?) && item.empty? }
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def drop_non_accepted_values
|
34
|
-
@hash.transform_values! { |array| array.reject { |item| !accepted_value? item } }
|
35
|
-
end
|
36
|
-
|
37
|
-
def accepted_value?(value)
|
38
|
-
@value = value
|
39
|
-
value_is_a_int || value_is_a_float || value_is_a_time_string
|
40
|
-
end
|
41
|
-
|
42
|
-
def to_float(object)
|
43
|
-
# Implemented a new to_float method, which replaces .to_f, because "7.5".to_f
|
44
|
-
# would correctly return 7.5, but "7,5" would incorrectly return 7.0.
|
45
|
-
object.is_a?(String) ? object.gsub(',','.').to_f : object.to_f
|
46
|
-
end
|
47
|
-
|
48
|
-
def value_is_a_int
|
49
|
-
@value.is_a? Integer
|
50
|
-
end
|
51
|
-
|
52
|
-
def value_is_a_float
|
53
|
-
@value.is_a? Float
|
54
|
-
end
|
55
|
-
|
56
|
-
def value_is_a_time_string
|
57
|
-
( @value.scan(/^[A-Za-z]+/).blank? && @value.scan(/\d{2}:\d{2}:\d{2}/).first ) ||
|
58
|
-
( @value.scan(/^[A-Za-z]+/).blank? && @value.scan(/\d{2}:\d{2}/).first )
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_integrate/application_exporter/auto_sum/format_data"
|
3
|
-
|
4
|
-
module EitilIntegrate::RubyXL
|
5
|
-
module AutoSum
|
6
|
-
class << self
|
7
|
-
|
8
|
-
def format_data
|
9
|
-
# format_time_strings
|
10
|
-
format_ints_to_floats
|
11
|
-
end
|
12
|
-
|
13
|
-
# outcommented method in favour of AutoSum#chronic_sum_array: no longer accept days, since the method excepts
|
14
|
-
# either hh:mm or hh:mm:ss
|
15
|
-
|
16
|
-
# def format_time_strings
|
17
|
-
# @hash.transform_values! { |array| array.map { |item| incomplete_time_string?(item) ? "#{item}:00" : item } }
|
18
|
-
# end
|
19
|
-
|
20
|
-
def incomplete_time_string?(string)
|
21
|
-
string.is_a?(String) && string.length == 5 && string.scan(/\d{2}:\d{2}/)
|
22
|
-
end
|
23
|
-
|
24
|
-
def format_ints_to_floats
|
25
|
-
@hash.transform_values! { |array| array.map { |item| item.is_a?(Integer) ? item.to_f : item } }
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_integrate/application_exporter/auto_sum/initialize"
|
3
|
-
|
4
|
-
module EitilIntegrate::RubyXL
|
5
|
-
module AutoSum
|
6
|
-
class << self
|
7
|
-
|
8
|
-
def perform(hashed_excel)
|
9
|
-
@hash = hashed_excel
|
10
|
-
|
11
|
-
drop_data
|
12
|
-
format_data
|
13
|
-
reduce_data
|
14
|
-
sum_data
|
15
|
-
present_data
|
16
|
-
|
17
|
-
@hash
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_integrate/application_exporter/auto_sum/present_data"
|
3
|
-
|
4
|
-
module EitilIntegrate::RubyXL
|
5
|
-
module AutoSum
|
6
|
-
class << self
|
7
|
-
|
8
|
-
# As final step, prepare the data for the excel file, according to formatting requirements.
|
9
|
-
|
10
|
-
def present_data
|
11
|
-
transform_floats_to_integers
|
12
|
-
transform_values_to_strings
|
13
|
-
set_title
|
14
|
-
end
|
15
|
-
|
16
|
-
def transform_floats_to_integers
|
17
|
-
@hash.transform_values! { |value| value.is_a?(Float) ? value.safe_to_i.round(3) : value }
|
18
|
-
end
|
19
|
-
|
20
|
-
def transform_values_to_strings
|
21
|
-
@hash.transform_values! { |value| value&.to_s }
|
22
|
-
end
|
23
|
-
|
24
|
-
def set_title
|
25
|
-
# @hash[0] = 'Totaal' unless @hash[0]
|
26
|
-
@hash[0] = 'Totaal'
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_integrate/application_exporter/auto_sum/reduce_data"
|
3
|
-
|
4
|
-
module EitilIntegrate::RubyXL
|
5
|
-
module AutoSum
|
6
|
-
class << self
|
7
|
-
|
8
|
-
def reduce_data
|
9
|
-
drop_multi_class_arrays
|
10
|
-
end
|
11
|
-
|
12
|
-
def drop_multi_class_arrays
|
13
|
-
@hash.transform_values! { |array| array.map(&:class).uniq.length == 1 ? array : [] }
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_integrate/application_exporter/auto_sum/sum_data"
|
3
|
-
|
4
|
-
module EitilIntegrate::RubyXL
|
5
|
-
module AutoSum
|
6
|
-
class << self
|
7
|
-
|
8
|
-
# Reduce values and alter data structure.
|
9
|
-
|
10
|
-
def sum_data
|
11
|
-
sum_floats
|
12
|
-
sum_time_strings
|
13
|
-
unpack_arrays
|
14
|
-
end
|
15
|
-
|
16
|
-
def sum_floats
|
17
|
-
@hash.transform_values! { |array| float_array?(array) ? [array.sum] : array }
|
18
|
-
end
|
19
|
-
|
20
|
-
def sum_time_strings
|
21
|
-
@hash.transform_values! { |array| time_string_array?(array) ? chronic_sum_array(array) : array }
|
22
|
-
end
|
23
|
-
|
24
|
-
def chronic_sum_array(array)
|
25
|
-
|
26
|
-
#total minutes, hours and days
|
27
|
-
tm, th, td = [0]*3
|
28
|
-
|
29
|
-
array.each do |time_string|
|
30
|
-
|
31
|
-
# add empty 0's, to avoid defining nil values when time values are absent
|
32
|
-
h, m, s = *time_string.split(':').map(&:to_i), *[0]*3
|
33
|
-
tm += m; th += h
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
# ALERT: the outcomment below is made to skip formatting days at all, so that
|
38
|
-
# – following eitje business logic – we currently only return an hh:mm notation
|
39
|
-
|
40
|
-
# # parsing times into maxes (60 m, 24 h, ∞ days)
|
41
|
-
# th += tm / 60
|
42
|
-
# tm = tm % 60
|
43
|
-
# td += th / 24
|
44
|
-
# th = th % 24
|
45
|
-
|
46
|
-
# # formatting strings
|
47
|
-
# sd = td.to_s
|
48
|
-
|
49
|
-
sh = th.to_s.rjust(2,'0')
|
50
|
-
sm = tm.to_s.rjust(2,'0')
|
51
|
-
|
52
|
-
if sm.to_i >= 60
|
53
|
-
sh = ( sh.to_i + (sm.to_i / 60 )).to_s
|
54
|
-
sm = ( sm.to_i % 60 ).to_s
|
55
|
-
end
|
56
|
-
|
57
|
-
# ALERT: the outcomment below is made to skip formatting days at all, so that
|
58
|
-
# – following eitje business logic – we currently only return an hh:mm notation
|
59
|
-
|
60
|
-
# [[sd, sh, sm].join(':')]
|
61
|
-
[[sh, sm].join(':')]
|
62
|
-
end
|
63
|
-
|
64
|
-
def format_time(time)
|
65
|
-
time.to_s.length == 1 ? "0#{time}" : time.to_s
|
66
|
-
end
|
67
|
-
|
68
|
-
def float_array?(array)
|
69
|
-
return false if array.empty?
|
70
|
-
array.all? { |item| item.is_a?(Float) }
|
71
|
-
end
|
72
|
-
|
73
|
-
def time_string_array?(array)
|
74
|
-
return false if array.empty?
|
75
|
-
array.all? { |item| item.is_a?(String) && item.scan(/\d{2}:\d{2}:\d{2}/) }
|
76
|
-
end
|
77
|
-
|
78
|
-
def unpack_arrays
|
79
|
-
@hash.transform_values! { |array| array.empty? ? nil : array.first }
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_integrate/application_exporter/auto_sum"
|
3
|
-
|
4
|
-
require_relative "auto_sum/initialize"
|
5
|
-
|
6
|
-
require_relative "auto_sum/drop_data"
|
7
|
-
require_relative "auto_sum/format_data"
|
8
|
-
require_relative "auto_sum/reduce_data"
|
9
|
-
require_relative "auto_sum/sum_data"
|
10
|
-
require_relative "auto_sum/present_data"
|
@@ -1,44 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_integrate/application_exporter/default_export"
|
3
|
-
|
4
|
-
require "eitil_integrate/application_exporter/initialize"
|
5
|
-
|
6
|
-
module EitilIntegrate::RubyXL
|
7
|
-
class ApplicationExporter
|
8
|
-
|
9
|
-
# The #create_file method is taken out of #export, to be overwritten by
|
10
|
-
# exports variants that want to loop over objects and call it multiple times.
|
11
|
-
# => e.g. the context of multiple Environment for a single Organisation
|
12
|
-
|
13
|
-
def export
|
14
|
-
prepare_export
|
15
|
-
create_file
|
16
|
-
process_export
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def prepare_export
|
22
|
-
validate_args_presence
|
23
|
-
validate_args_value
|
24
|
-
end
|
25
|
-
|
26
|
-
def create_file
|
27
|
-
name_sheet
|
28
|
-
set_data
|
29
|
-
validate_data
|
30
|
-
fill_messages
|
31
|
-
fill_header
|
32
|
-
fill_file
|
33
|
-
end
|
34
|
-
|
35
|
-
def process_export
|
36
|
-
style_file
|
37
|
-
log_state
|
38
|
-
save_file
|
39
|
-
end
|
40
|
-
|
41
|
-
alias_method :base_create_file, :create_file
|
42
|
-
|
43
|
-
end
|
44
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_integrate/application_exporter/helpers"
|
3
|
-
|
4
|
-
require "eitil_integrate/application_exporter/initialize"
|
5
|
-
|
6
|
-
module EitilIntegrate::RubyXL
|
7
|
-
class ApplicationExporter
|
8
|
-
|
9
|
-
def array_to_indexed_hash(array)
|
10
|
-
array = array_nils_substituted(array)
|
11
|
-
array = array_values_strf(array)
|
12
|
-
array.flatten.map.with_index { |item, index| { "#{index}": item } }.inject &:merge
|
13
|
-
end
|
14
|
-
|
15
|
-
def array_nils_substituted(array)
|
16
|
-
array.map { |value| value || '' }
|
17
|
-
end
|
18
|
-
|
19
|
-
def array_values_strf(array)
|
20
|
-
array.map &:to_s
|
21
|
-
end
|
22
|
-
|
23
|
-
def sanitize_int(integer)
|
24
|
-
(integer.nan? || integer.infinite?) ? 0 : integer
|
25
|
-
end
|
26
|
-
|
27
|
-
def pretty_date_range
|
28
|
-
date_range.to_s.gsub '..', ' – '
|
29
|
-
end
|
30
|
-
|
31
|
-
def strf_date_range
|
32
|
-
date_range.map &:to_s
|
33
|
-
end
|
34
|
-
|
35
|
-
def double_digit_time(time)
|
36
|
-
time.to_s.length == 1 ? "0#{time}" : time.to_s
|
37
|
-
end
|
38
|
-
|
39
|
-
def format_minutes(minutes)
|
40
|
-
hours = double_digit_time(minutes / 60)
|
41
|
-
minutes = double_digit_time(minutes % 60)
|
42
|
-
"#{hours}:#{minutes}"
|
43
|
-
end
|
44
|
-
|
45
|
-
def name_sheet(name='Worksheet')
|
46
|
-
sheet.sheet_name = name
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_integrate/application_exporter/infos"
|
3
|
-
|
4
|
-
require "eitil_integrate/application_exporter/initialize"
|
5
|
-
|
6
|
-
module EitilIntegrate::RubyXL
|
7
|
-
class ApplicationExporter
|
8
|
-
class << self
|
9
|
-
|
10
|
-
attr_accessor :info
|
11
|
-
|
12
|
-
def set_info(_h)
|
13
|
-
@info ||= {}
|
14
|
-
k, v = *_h.first
|
15
|
-
@info[k] = v
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_integrate/application_exporter/initialize"
|
3
|
-
|
4
|
-
require "eitil_core/setters/set_ivars"
|
5
|
-
require "eitil_core/argument_helpers/all_kwargs_to_ivars"
|
6
|
-
require "action_view"
|
7
|
-
require "rubyXL"
|
8
|
-
|
9
|
-
module EitilIntegrate
|
10
|
-
module RubyXL
|
11
|
-
class ApplicationExporter
|
12
|
-
|
13
|
-
include ActionView::Helpers::NumberHelper
|
14
|
-
|
15
|
-
attr_accessor :book, :sheet, :x, :y, :start_date, :end_date, :date_range, :write_log
|
16
|
-
|
17
|
-
def initialize(attributes={})
|
18
|
-
|
19
|
-
@start_date ||= attributes[:start_date]
|
20
|
-
@end_date ||= attributes[:end_date]
|
21
|
-
|
22
|
-
set_ivars :start_date, :end_date, :date_range
|
23
|
-
|
24
|
-
@book = ::RubyXL::Workbook.new
|
25
|
-
@sheet = @book.worksheets[0]
|
26
|
-
@x ||= 0
|
27
|
-
@y ||= 0
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_integrate/application_exporter/log_state"
|
3
|
-
|
4
|
-
module EitilIntegrate::RubyXL
|
5
|
-
class ApplicationExporter
|
6
|
-
|
7
|
-
private
|
8
|
-
|
9
|
-
def log_state
|
10
|
-
|
11
|
-
return unless write_log == true
|
12
|
-
|
13
|
-
# create_log_sheet
|
14
|
-
book.add_worksheet('log')
|
15
|
-
|
16
|
-
# manage sheets
|
17
|
-
previous_sheet = @sheet.sheet_name
|
18
|
-
@sheet = @book["log"]
|
19
|
-
|
20
|
-
# manage coordinates
|
21
|
-
previous_x = @x
|
22
|
-
@x = 0
|
23
|
-
|
24
|
-
# log everything we want to log
|
25
|
-
report_state
|
26
|
-
|
27
|
-
# style logs
|
28
|
-
base_style_first_x_columns_width 1, 40
|
29
|
-
style_first_column_bold
|
30
|
-
|
31
|
-
# restore what was previously active
|
32
|
-
@sheet = @book[previous_sheet]
|
33
|
-
@x = previous_x
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
def report_state
|
38
|
-
instance_variables.each do |ivar|
|
39
|
-
|
40
|
-
variable_name = ivar.to_s
|
41
|
-
variable_value = format_value(instance_variable_get(ivar))
|
42
|
-
|
43
|
-
array_to_row [variable_name, variable_value]
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
# formatting the values to a human readably format is important, because otherwise Excel warns
|
49
|
-
# users on safety when opening the file.
|
50
|
-
def format_value(value)
|
51
|
-
value_class = value.class
|
52
|
-
|
53
|
-
if value_class == Hash
|
54
|
-
value.map {|k,v| "#{k.to_s.split('_').map(&:capitalize).join(' ')}: #{v}"}.join(' // ')
|
55
|
-
|
56
|
-
elsif value_class == Array && value.all? { |item| item.class.superclass == ApplicationRecord }
|
57
|
-
"#{value.class} #{value.map(&:id).join(', ')}"
|
58
|
-
|
59
|
-
elsif value_class.superclass == ApplicationRecord
|
60
|
-
"#{value.class} ##{value.id}"
|
61
|
-
|
62
|
-
elsif value_class.superclass == ActiveRecord::Relation
|
63
|
-
"#{value.class.to_s.split('::').first} #{value.ids.to_s.delete('[]')}"
|
64
|
-
|
65
|
-
elsif value_class.superclass == ActiveRecord::Associations::CollectionProxy
|
66
|
-
"#{value.class.to_s.split('::').first} #{value.ids.to_s.delete('[]')}"
|
67
|
-
|
68
|
-
elsif value_class == RubyXL::Workbook
|
69
|
-
value_class.name
|
70
|
-
|
71
|
-
elsif value_class == RubyXL::Worksheet
|
72
|
-
value_class.name
|
73
|
-
|
74
|
-
else
|
75
|
-
value.to_s
|
76
|
-
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_integrate/application_exporter/selectors"
|
3
|
-
|
4
|
-
require "eitil_integrate/application_exporter/initialize"
|
5
|
-
|
6
|
-
module EitilIntegrate::RubyXL
|
7
|
-
class ApplicationExporter
|
8
|
-
|
9
|
-
private
|
10
|
-
|
11
|
-
# rows
|
12
|
-
|
13
|
-
def current_row
|
14
|
-
x
|
15
|
-
end
|
16
|
-
|
17
|
-
def previous_row
|
18
|
-
x - 1
|
19
|
-
end
|
20
|
-
|
21
|
-
def next_row
|
22
|
-
x + 1
|
23
|
-
end
|
24
|
-
|
25
|
-
def first_row
|
26
|
-
0
|
27
|
-
end
|
28
|
-
|
29
|
-
# columns
|
30
|
-
|
31
|
-
def current_column
|
32
|
-
y
|
33
|
-
end
|
34
|
-
|
35
|
-
def previous_column
|
36
|
-
y - 1
|
37
|
-
end
|
38
|
-
|
39
|
-
def next_column
|
40
|
-
y + 1
|
41
|
-
end
|
42
|
-
|
43
|
-
def first_column
|
44
|
-
0
|
45
|
-
end
|
46
|
-
|
47
|
-
# RubyXL object selectors for rows. For columns I have not found a RubyXL object,
|
48
|
-
# or a practical way of accessing the cells of a column, yet.
|
49
|
-
|
50
|
-
def method_missing(_method, *args, &block)
|
51
|
-
m = _method.to_s
|
52
|
-
super _method unless m.include?('row') and m.ends_with?('_object')
|
53
|
-
super _method unless respond_to? m.delete_suffix!('_object'), true
|
54
|
-
sheet[send(m)]
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_integrate/application_exporter/setters"
|
3
|
-
|
4
|
-
require "eitil_integrate/application_exporter/initialize"
|
5
|
-
|
6
|
-
module EitilIntegrate::RubyXL
|
7
|
-
class ApplicationExporter
|
8
|
-
|
9
|
-
# The date setter methods allow Exporters to receive dates as strings, which are
|
10
|
-
# required to prevent serialization errors in perform_later background jobs.
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def set_start_date
|
15
|
-
@start_date.is_a?(Date) ? @start_date : Date.parse(@start_date) if @start_date
|
16
|
-
end
|
17
|
-
|
18
|
-
def set_end_date
|
19
|
-
@end_date.is_a?(Date) ? @end_date : Date.parse(@end_date) if @end_date
|
20
|
-
end
|
21
|
-
|
22
|
-
def set_date_range
|
23
|
-
@start_date..@end_date if @start_date && @end_date
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_integrate/application_exporter/store_file"
|
3
|
-
|
4
|
-
require "eitil_integrate/application_exporter/initialize"
|
5
|
-
require "eitil_core/setters/set_ivars"
|
6
|
-
|
7
|
-
module EitilIntegrate::RubyXL
|
8
|
-
class ApplicationExporter
|
9
|
-
|
10
|
-
attr_accessor :storage_path
|
11
|
-
|
12
|
-
private
|
13
|
-
|
14
|
-
def save_file
|
15
|
-
set_ivars :storage_path
|
16
|
-
save_book
|
17
|
-
run_after_save_effects
|
18
|
-
@storage_path
|
19
|
-
end
|
20
|
-
|
21
|
-
def set_storage_path
|
22
|
-
"#{Rails.root}/data/#{file_name}"
|
23
|
-
end
|
24
|
-
|
25
|
-
def file_name
|
26
|
-
"#{file_tile}|#{file_timestamp}.#{file_extension}"
|
27
|
-
end
|
28
|
-
|
29
|
-
def file_tile
|
30
|
-
@file_title || self.class.name.snakecase
|
31
|
-
end
|
32
|
-
|
33
|
-
def file_timestamp
|
34
|
-
@file_timestamp || Time.now.strftime("%Y-%m-%d|%H-%M-%S")
|
35
|
-
end
|
36
|
-
|
37
|
-
def file_extension
|
38
|
-
@file_extension || "xlsx"
|
39
|
-
end
|
40
|
-
|
41
|
-
def save_book
|
42
|
-
book.write @storage_path
|
43
|
-
end
|
44
|
-
|
45
|
-
def run_after_save_effects
|
46
|
-
# nil fallback for if the application class (which inherits from ApplicationExporter) has no method #run_after_save_effects
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
@@ -1,104 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_integrate/application_exporter/style_cells"
|
3
|
-
|
4
|
-
require "eitil_integrate/application_exporter/initialize"
|
5
|
-
|
6
|
-
module EitilIntegrate::RubyXL
|
7
|
-
class ApplicationExporter
|
8
|
-
|
9
|
-
COLOURS = { white: 'ffffff', black: '000000', red: 'FF0000', blue: '0000FF', green: '00FF00', yellow: 'FFFF00',
|
10
|
-
cyan: '00FFFF', magenta: 'FF00FF', dark_grey: '464646', grey: '7E7E7E', light_grey: 'C1C1C1',
|
11
|
-
eitje_blue: '0496FF' }
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def style_file
|
16
|
-
style_general
|
17
|
-
style_custom
|
18
|
-
end
|
19
|
-
|
20
|
-
def style_general
|
21
|
-
style_row_height
|
22
|
-
style_column_width
|
23
|
-
style_first_row_bold
|
24
|
-
style_first_column_bold
|
25
|
-
style_first_column_width
|
26
|
-
end
|
27
|
-
|
28
|
-
def style_custom
|
29
|
-
%i[
|
30
|
-
style_first_x_columns_width
|
31
|
-
style_x_columns_width
|
32
|
-
style_first_x_rows_height
|
33
|
-
style_x_rows_height
|
34
|
-
].each { |_method| safe_send _method }
|
35
|
-
end
|
36
|
-
|
37
|
-
# multi rows
|
38
|
-
|
39
|
-
def style_row_height(height = 15)
|
40
|
-
base_style_x_rows_height row_indices, height
|
41
|
-
end
|
42
|
-
|
43
|
-
def style_first_x_rows_height(n_rows, height)
|
44
|
-
base_style_x_rows_height (0...n_rows), height
|
45
|
-
end
|
46
|
-
|
47
|
-
def style_x_rows_height(row_indices = [], height)
|
48
|
-
row_indices.each { |i| @sheet.change_row_height(i, height) }
|
49
|
-
end
|
50
|
-
|
51
|
-
alias_method :base_style_x_rows_height, :style_x_rows_height
|
52
|
-
|
53
|
-
# multi columns
|
54
|
-
|
55
|
-
def style_column_width(width = 40)
|
56
|
-
base_style_x_columns_width column_indices, width
|
57
|
-
end
|
58
|
-
|
59
|
-
def style_first_x_columns_width(n_columns, width)
|
60
|
-
base_style_x_columns_width (0...n_columns), width
|
61
|
-
end
|
62
|
-
|
63
|
-
def style_first_column_width(width = 35)
|
64
|
-
style_first_x_columns_width 1, width
|
65
|
-
end
|
66
|
-
|
67
|
-
alias_method :base_style_first_x_columns_width, :style_first_x_columns_width
|
68
|
-
|
69
|
-
def style_x_columns_width(column_indices = [], width)
|
70
|
-
column_indices.each { |i| @sheet.change_column_width(i, width) }
|
71
|
-
end
|
72
|
-
|
73
|
-
alias_method :base_style_x_columns_width, :style_x_columns_width
|
74
|
-
|
75
|
-
# single row
|
76
|
-
|
77
|
-
def style_first_row_bold
|
78
|
-
style_row_bold first_row
|
79
|
-
end
|
80
|
-
|
81
|
-
def style_row_bold(row)
|
82
|
-
@sheet.change_row_bold(row, true)
|
83
|
-
end
|
84
|
-
|
85
|
-
def style_row_font_colour(row, colour)
|
86
|
-
@sheet.change_row_font_color row, COLOURS[colour.to_sym]
|
87
|
-
end
|
88
|
-
|
89
|
-
def style_row_background_colour(row, colour)
|
90
|
-
sheet[row].cells.each { |cell| cell.change_fill COLOURS[colour.to_sym] }
|
91
|
-
end
|
92
|
-
|
93
|
-
# single column
|
94
|
-
|
95
|
-
def style_first_column_bold
|
96
|
-
style_column_bold first_column
|
97
|
-
end
|
98
|
-
|
99
|
-
def style_column_bold(column)
|
100
|
-
@sheet.change_column_bold(column, true)
|
101
|
-
end
|
102
|
-
|
103
|
-
end
|
104
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_integrate/application_exporter/validations"
|
3
|
-
|
4
|
-
require "eitil_integrate/application_exporter/initialize"
|
5
|
-
require "eitil_core/errors/raise_error"
|
6
|
-
|
7
|
-
module EitilIntegrate::RubyXL
|
8
|
-
class ApplicationExporter
|
9
|
-
|
10
|
-
def validate_args_presence(*args)
|
11
|
-
args.each do |arg|
|
12
|
-
unless instance_variable_get "@#{arg}"
|
13
|
-
raise_error 'ExportArgumentsNotSetError', 'Set all required arguments. (Be aware that nil values will fail the test.)'
|
14
|
-
end
|
15
|
-
end
|
16
|
-
true
|
17
|
-
end
|
18
|
-
|
19
|
-
def validate_args_value
|
20
|
-
# Empty holder to prevent NoMethodError in DefaultExporter#export.
|
21
|
-
end
|
22
|
-
|
23
|
-
def validate_data
|
24
|
-
# Empty holder to prevent NoMethodError in DefaultExporter#export.
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_integrate/application_exporter/write_cells"
|
3
|
-
|
4
|
-
require "eitil_integrate/application_exporter/initialize"
|
5
|
-
|
6
|
-
module EitilIntegrate::RubyXL
|
7
|
-
class ApplicationExporter
|
8
|
-
|
9
|
-
def new_row(row_hash)
|
10
|
-
row_hash.each { |x_axis, title| @sheet.add_cell(x, x_axis.to_s.to_i, title) }
|
11
|
-
@x += 1
|
12
|
-
end
|
13
|
-
|
14
|
-
def empty_row
|
15
|
-
@x += 1
|
16
|
-
end
|
17
|
-
|
18
|
-
def empty_rows(n_rows)
|
19
|
-
@x += n_rows
|
20
|
-
end
|
21
|
-
|
22
|
-
def new_column(column_hash)
|
23
|
-
column_hash.each { |y_axis, title| @sheet.add_cell(y_axis.to_s.to_i, y, title) }
|
24
|
-
@y += 1
|
25
|
-
end
|
26
|
-
|
27
|
-
def empty_column
|
28
|
-
@y += 1
|
29
|
-
end
|
30
|
-
|
31
|
-
def empty_columns(n_columns)
|
32
|
-
@y += n_columns
|
33
|
-
end
|
34
|
-
|
35
|
-
def rows
|
36
|
-
@sheet.sheet_data.rows
|
37
|
-
end
|
38
|
-
|
39
|
-
def row_indices
|
40
|
-
(0...rows.count).to_a
|
41
|
-
end
|
42
|
-
|
43
|
-
def columns
|
44
|
-
# RubyXl does not seem to be purposed around columns, but merely handle rows properly.
|
45
|
-
end
|
46
|
-
|
47
|
-
def column_indices
|
48
|
-
n_rows = rows.map { |r| r&.cells&.count }.compact.max #temporary hack
|
49
|
-
(0...n_rows).to_a
|
50
|
-
end
|
51
|
-
|
52
|
-
def array_to_row(array)
|
53
|
-
new_row array_to_indexed_hash(array)
|
54
|
-
end
|
55
|
-
|
56
|
-
def row_values(row_index)
|
57
|
-
rows.dig(row_index).cells.map &:value
|
58
|
-
end
|
59
|
-
|
60
|
-
def column_values(column_index)
|
61
|
-
rows.map { |row| row&.cells&.dig(column_index)&.value }
|
62
|
-
end
|
63
|
-
|
64
|
-
def all_column_values
|
65
|
-
column_indices.map { |i| { i => column_values(i) } }.inject &:merge
|
66
|
-
end
|
67
|
-
|
68
|
-
def all_row_values
|
69
|
-
row_indices.map { |i| { i => row_values(i) } }.inject &:merge
|
70
|
-
end
|
71
|
-
|
72
|
-
def sum_row
|
73
|
-
new_row EitilIntegrate::RubyXL::AutoSum.perform(all_column_values)
|
74
|
-
style_row_bold previous_row
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
|
2
|
-
# require "eitil_integrate/application_exporter/write_messages"
|
3
|
-
|
4
|
-
require "eitil_integrate/application_exporter/initialize"
|
5
|
-
|
6
|
-
module EitilIntegrate::RubyXL
|
7
|
-
class ApplicationExporter
|
8
|
-
|
9
|
-
def fill_messages
|
10
|
-
# nil fallback for if the exporter class has no method #fill_messages
|
11
|
-
end
|
12
|
-
|
13
|
-
def write_message(message)
|
14
|
-
new_row({ '0': message })
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# require "eitil_integrate/application_exporter"
|
2
|
-
|
3
|
-
# base file, which is required by all others
|
4
|
-
require_relative "application_exporter/initialize"
|
5
|
-
|
6
|
-
# temp file, with methods that should, at some point, moved elsewhere
|
7
|
-
require_relative "application_exporter/helpers"
|
8
|
-
|
9
|
-
# files split by theme and purpose, feel free to cherry-pick
|
10
|
-
require_relative "application_exporter/default_export"
|
11
|
-
require_relative "application_exporter/validations"
|
12
|
-
require_relative "application_exporter/write_cells"
|
13
|
-
require_relative "application_exporter/write_messages"
|
14
|
-
require_relative "application_exporter/style_cells"
|
15
|
-
require_relative "application_exporter/store_file"
|
16
|
-
require_relative "application_exporter/setters"
|
17
|
-
require_relative "application_exporter/selectors"
|
18
|
-
require_relative "application_exporter/infos"
|
19
|
-
require_relative "application_exporter/log_state"
|
20
|
-
|
21
|
-
# the AutoSum module, which is a seperately functioning module (service)
|
22
|
-
require_relative "application_exporter/auto_sum"
|