Module: DataExportHelper

Included in:
CsvExportService, DataCacheService, PdfExportService, XlsxExportService
Defined in:
app/models/concerns/data_export_helper.rb

Instance Method Summary collapse

Instance Method Details

#convert_parameters(parameters) ⇒ Object



3
4
5
6
7
8
9
# File 'app/models/concerns/data_export_helper.rb', line 3

def convert_parameters(parameters)
  @params = {}
  parameters.each do |k, v|
    @params.merge! k.to_sym => v.send(RailsData.config.mapping[@data_list.parameters[k].to_sym][:output])
  end
  @params
end

#field_result(object, index) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/concerns/data_export_helper.rb', line 24

def field_result(object, index)
  results = []
  @config_table.columns.each do |_, column|
    params = column[:field].parameters.to_combined_h
    if Array(params[:key]).include? :index
      results << column[:field].call(object, index)
    elsif params[:key]
      results << column[:field].call(object, **@params.slice(params[:key]))
    elsif params[:key].blank? && params[:req]
      results << column[:field].call(object)
    else
      results << nil
    end
  end

  results
end


42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/concerns/data_export_helper.rb', line 42

def footer_result
  results = []

  @config_table.columns.each do |_, column|
    if column[:footer].respond_to?(:call)
      results << column[:footer].call
    else
      results << column[:footer]
    end
  end
  results
end

#header_resultObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/concerns/data_export_helper.rb', line 11

def header_result
  results = []

  @config_table.columns.each do |_, column|
    if column[:header].respond_to?(:call)
      results << column[:header].call
    else
      results << column[:header]
    end
  end
  results
end