eitil 1.0.2 → 1.0.3.e.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +0 -1
- data/eitil_core/README.md +60 -4
- 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_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 +32 -1
- data/lib/eitil/version.rb +1 -1
- metadata +57 -5
- data/lib/eitil/engine.rb +0 -38
- data/lib/tasks/eitil_tasks.rake +0 -4
@@ -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
|
@@ -0,0 +1,97 @@
|
|
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
|
+
end
|
26
|
+
|
27
|
+
def style_custom
|
28
|
+
%i[
|
29
|
+
style_first_x_columns_width
|
30
|
+
style_x_columns_width
|
31
|
+
style_first_x_rows_height
|
32
|
+
style_x_rows_height
|
33
|
+
].each { |_method| safe_send _method }
|
34
|
+
end
|
35
|
+
|
36
|
+
# multi rows
|
37
|
+
|
38
|
+
def style_row_height(height = 15)
|
39
|
+
base_style_x_rows_height row_indices, height
|
40
|
+
end
|
41
|
+
|
42
|
+
def style_first_x_rows_height(n_rows, height)
|
43
|
+
base_style_x_rows_height (0...n_rows), height
|
44
|
+
end
|
45
|
+
|
46
|
+
def style_x_rows_height(row_indices = [], height)
|
47
|
+
row_indices.each { |i| @sheet.change_row_height(i, height) }
|
48
|
+
end
|
49
|
+
|
50
|
+
alias_method :base_style_x_rows_height, :style_x_rows_height
|
51
|
+
|
52
|
+
# multi columns
|
53
|
+
|
54
|
+
def style_column_width(width = 40)
|
55
|
+
base_style_x_columns_width column_indices, width
|
56
|
+
end
|
57
|
+
|
58
|
+
def style_first_x_columns_width(n_columns, width)
|
59
|
+
base_style_x_columns_width (0...n_columns), width
|
60
|
+
end
|
61
|
+
|
62
|
+
def style_x_columns_width(column_indices = [], width)
|
63
|
+
column_indices.each { |i| @sheet.change_column_width(i, width) }
|
64
|
+
end
|
65
|
+
|
66
|
+
alias_method :base_style_x_columns_width, :style_x_columns_width
|
67
|
+
|
68
|
+
# single row
|
69
|
+
|
70
|
+
def style_first_row_bold
|
71
|
+
style_row_bold first_row
|
72
|
+
end
|
73
|
+
|
74
|
+
def style_row_bold(row)
|
75
|
+
@sheet.change_row_bold(row, true)
|
76
|
+
end
|
77
|
+
|
78
|
+
def style_row_font_colour(row, colour)
|
79
|
+
@sheet.change_row_font_color row, COLOURS[colour.to_sym]
|
80
|
+
end
|
81
|
+
|
82
|
+
def style_row_background_colour(row, colour)
|
83
|
+
sheet[row].cells.each { |cell| cell.change_fill COLOURS[colour.to_sym] }
|
84
|
+
end
|
85
|
+
|
86
|
+
# single column
|
87
|
+
|
88
|
+
def style_first_column_bold
|
89
|
+
style_column_bold first_column
|
90
|
+
end
|
91
|
+
|
92
|
+
def style_column_bold(column)
|
93
|
+
@sheet.change_column_bold(column, true)
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|