eitil 1.0.1.e.4 → 1.0.4
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/Rakefile +0 -1
- data/eitil_core/README.md +93 -4
- data/eitil_core/lib/eitil_core.rb +1 -0
- data/eitil_core/lib/eitil_core/argument_helpers.rb +8 -0
- data/eitil_core/lib/eitil_core/argument_helpers/all_args_to_ivars_bang.rb +15 -0
- data/eitil_core/lib/eitil_core/argument_helpers/all_kwargs_to_ivars_bang.rb +15 -0
- data/eitil_core/lib/eitil_core/argument_helpers/args_to_h.rb +15 -0
- data/eitil_core/lib/eitil_core/argument_helpers/args_to_h_bang.rb +17 -0
- data/eitil_core/lib/eitil_core/argument_helpers/args_to_ivars_bang.rb +15 -0
- data/eitil_core/lib/eitil_core/float/safe_to_i.rb +3 -0
- data/eitil_core/lib/eitil_core/lookups.rb +2 -1
- data/eitil_core/lib/eitil_core/lookups/gem_path.rb +10 -0
- data/eitil_core/lib/eitil_core/mocks.rb +6 -0
- data/eitil_core/lib/eitil_core/mocks/array.rb +39 -0
- data/eitil_core/lib/eitil_core/mocks/hash.rb +36 -0
- data/eitil_core/lib/eitil_core/mocks/string.rb +11 -0
- data/eitil_integrate/README.md +11 -0
- data/eitil_integrate/lib/eitil_integrate.rb +4 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter.rb +22 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum.rb +10 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/drop_data.rb +54 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/format_data.rb +27 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/initialize.rb +22 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/present_data.rb +31 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/reduce_data.rb +18 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/auto_sum/sum_data.rb +56 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/default_export.rb +43 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/helpers.rb +50 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/infos.rb +20 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/initialize.rb +28 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/lookups.rb +40 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/selectors.rb +58 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/setters.rb +27 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/store_file.rb +34 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/style_cells.rb +97 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/validations.rb +28 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/write_cells.rb +78 -0
- data/eitil_integrate/lib/eitil_integrate/application_exporter/write_messages.rb +18 -0
- data/eitil_support/lib/eitil_support/directory/lookups.rb +3 -0
- data/lib/eitil.rb +0 -1
- data/lib/eitil/all.rb +2 -3
- data/lib/eitil/railtie.rb +28 -1
- data/lib/eitil/version.rb +1 -1
- metadata +62 -6
- data/lib/eitil/engine.rb +0 -38
- data/lib/tasks/eitil_tasks.rake +0 -4
@@ -0,0 +1,27 @@
|
|
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
|
+
def format_time_strings
|
14
|
+
@hash.transform_values! { |array| array.map { |item| incomplete_time_string?(item) ? "#{item}:00" : item } }
|
15
|
+
end
|
16
|
+
|
17
|
+
def incomplete_time_string?(string)
|
18
|
+
string.is_a?(String) && string.length == 5 && string.scan(/\d{2}:\d{2}/)
|
19
|
+
end
|
20
|
+
|
21
|
+
def format_ints_to_floats
|
22
|
+
@hash.transform_values! { |array| array.map { |item| item.is_a?(Integer) ? item.to_f : item } }
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
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
|
@@ -0,0 +1,31 @@
|
|
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
|
@@ -0,0 +1,18 @@
|
|
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
|
@@ -0,0 +1,56 @@
|
|
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
|
+
sum = array.map { |item| ChronicDuration.parse(item) }.compact.sum
|
26
|
+
hours = format_time(sum / (60 * 60))
|
27
|
+
sum = sum % (60 * 60)
|
28
|
+
minutes = format_time(sum / 60)
|
29
|
+
seconds = format_time(sum % 60)
|
30
|
+
|
31
|
+
# currently doesn't return seconds, since those will never
|
32
|
+
# be set (?) and screw the consistency of data formatting
|
33
|
+
["#{hours}:#{minutes}"]
|
34
|
+
end
|
35
|
+
|
36
|
+
def format_time(time)
|
37
|
+
time.to_s.length == 1 ? "0#{time}" : time.to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
def float_array?(array)
|
41
|
+
return false if array.empty?
|
42
|
+
array.all? { |item| item.is_a?(Float) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def time_string_array?(array)
|
46
|
+
return false if array.empty?
|
47
|
+
array.all? { |item| item.is_a?(String) && item.scan(/\d{2}:\d{2}:\d{2}/) }
|
48
|
+
end
|
49
|
+
|
50
|
+
def unpack_arrays
|
51
|
+
@hash.transform_values! { |array| array.empty? ? nil : array.first }
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,43 @@
|
|
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
|
+
save_file
|
38
|
+
end
|
39
|
+
|
40
|
+
alias_method :base_create_file, :create_file
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,50 @@
|
|
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
|
@@ -0,0 +1,20 @@
|
|
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
|
@@ -0,0 +1,28 @@
|
|
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
|
+
|
7
|
+
# EitilIntegrate::RubyXL::ApplicationExporter
|
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
|
16
|
+
|
17
|
+
def initialize(attributes={})
|
18
|
+
all_kwargs_to_ivars binding, :attributes
|
19
|
+
set_ivars :start_date, :end_date, :date_range
|
20
|
+
@book = ::RubyXL::Workbook.new
|
21
|
+
@sheet = @book.worksheets[0]
|
22
|
+
@x ||= 0
|
23
|
+
@y ||= 0
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
# require "eitil_integrate/application_exporter/lookups"
|
3
|
+
|
4
|
+
require "eitil_integrate/application_exporter/initialize"
|
5
|
+
require "eitil_support/directory"
|
6
|
+
|
7
|
+
module EitilIntegrate::RubyXL
|
8
|
+
class ApplicationExporter
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
def exporter_paths
|
13
|
+
EitilSupport::Directory.files('app/exporters/exporters').select { |path| path.end_with? '_exporter.rb' }
|
14
|
+
end
|
15
|
+
|
16
|
+
def exporter_names
|
17
|
+
exporter_paths.map { |path| path.split('/').last.remove('.rb').camelcase }
|
18
|
+
end
|
19
|
+
|
20
|
+
def exporter_constants
|
21
|
+
exporter_names.map &:constantize
|
22
|
+
end
|
23
|
+
|
24
|
+
def exporter_infos
|
25
|
+
exporter_constants.map { |_c| { "#{_c}": _c.info || {} } }.inject &:merge
|
26
|
+
end
|
27
|
+
|
28
|
+
alias_method :taxonomy, :exporter_infos
|
29
|
+
|
30
|
+
def exporter_info(exporter, info)
|
31
|
+
exporter_infos[exporter]&.dig(info)
|
32
|
+
end
|
33
|
+
|
34
|
+
def exporter_params
|
35
|
+
exporter_infos.transform_values { |v| [v[:required], v[:optional]].flatten.compact }
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,58 @@
|
|
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
|
@@ -0,0 +1,27 @@
|
|
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
|
@@ -0,0 +1,34 @@
|
|
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/#{self.class.name.snakecase}_#{DateTime.now.prettify}.xlsx"
|
23
|
+
end
|
24
|
+
|
25
|
+
def save_book
|
26
|
+
book.write @storage_path
|
27
|
+
end
|
28
|
+
|
29
|
+
def run_after_save_effects
|
30
|
+
# nil fallback for if the application class (which inherits from ApplicationExporter) has no method #run_after_save_effects
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|