Class: RecordList

Inherits:
ApplicationRecord
  • Object
show all
Defined in:
app/models/rails_data/record_list.rb

Instance Method Summary collapse

Instance Method Details

#converted_parametersObject



25
26
27
28
29
30
31
# File 'app/models/rails_data/record_list.rb', line 25

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

#field_result(object) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/rails_data/record_list.rb', line 37

def field_result(object)
  results = {}
  @config_table.columns.each do |key, column|
    if column[:field].arity == 1
      results[key] = column[:field].call(object)
    else
      results[key] = nil
    end
  end

  results
end

#file_name(format) ⇒ Object



64
65
66
67
# File 'app/models/rails_data/record_list.rb', line 64

def file_name(format)
  name = self.id || 'example'
  "#{name}.#{format}"
end

#initialize_tableObject



19
20
21
22
23
# File 'app/models/rails_data/record_list.rb', line 19

def initialize_table
  @config_table = data_list.config_table
  @record = @config_table.record.call(converted_parameters)
  @config_table
end

#runObject



8
9
10
# File 'app/models/rails_data/record_list.rb', line 8

def run
  to_table
end

#to_pdfObject



55
56
57
58
# File 'app/models/rails_data/record_list.rb', line 55

def to_pdf
  @config_pdf ||= data_list.config_pdf.new(self.columns)
  @config_pdf.render
end

#to_tableObject



12
13
14
15
16
17
# File 'app/models/rails_data/record_list.rb', line 12

def to_table
  initialize_table
  self.to_table_items
  self.done = true
  self.save
end

#to_table_itemsObject



33
34
35
# File 'app/models/rails_data/record_list.rb', line 33

def to_table_items
  self.columns = field_result(@record)
end

#to_xlsxObject



50
51
52
53
# File 'app/models/rails_data/record_list.rb', line 50

def to_xlsx
  @config_excel = data_list.config_excel.new(self.columns)
  @config_excel.render
end

#xlsx_file_nameObject



60
61
62
# File 'app/models/rails_data/record_list.rb', line 60

def xlsx_file_name
  @config_excel.file_name || "#{self.id}.xlsx"
end