Class: RecordList
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- RecordList
- Defined in:
- app/models/rails_data/record_list.rb
Instance Method Summary collapse
- #converted_parameters ⇒ Object
- #field_result(object) ⇒ Object
- #file_name(format) ⇒ Object
- #initialize_table ⇒ Object
- #run ⇒ Object
- #to_pdf ⇒ Object
- #to_table ⇒ Object
- #to_table_items ⇒ Object
- #to_xlsx ⇒ Object
- #xlsx_file_name ⇒ Object
Instance Method Details
#converted_parameters ⇒ Object
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_table ⇒ Object
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 |
#run ⇒ Object
8 9 10 |
# File 'app/models/rails_data/record_list.rb', line 8 def run to_table end |
#to_pdf ⇒ Object
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_table ⇒ Object
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_items ⇒ Object
33 34 35 |
# File 'app/models/rails_data/record_list.rb', line 33 def to_table_items self.columns = field_result(@record) end |
#to_xlsx ⇒ Object
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_name ⇒ Object
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 |