Class: Formily::SubmittedDataTable
- Inherits:
-
Object
- Object
- Formily::SubmittedDataTable
- Defined in:
- lib/formily/submitted_data_table.rb
Overview
Helper class for display & convert submitted data
Instance Method Summary collapse
- #headers ⇒ Object
-
#initialize(form, res) ⇒ SubmittedDataTable
constructor
A new instance of SubmittedDataTable.
- #rows ⇒ Object
- #to_csv ⇒ Object
Constructor Details
#initialize(form, res) ⇒ SubmittedDataTable
Returns a new instance of SubmittedDataTable.
8 9 10 11 12 13 14 |
# File 'lib/formily/submitted_data_table.rb', line 8 def initialize(form, res) @form = form @headers = ['related'] + @form.inputs.pluck(:name) + ['date'] @res = res @rows = [] get_data end |
Instance Method Details
#headers ⇒ Object
16 17 18 |
# File 'lib/formily/submitted_data_table.rb', line 16 def headers @headers end |
#rows ⇒ Object
20 21 22 |
# File 'lib/formily/submitted_data_table.rb', line 20 def rows @rows end |
#to_csv ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/formily/submitted_data_table.rb', line 24 def to_csv CSV.generate do |csv| csv << (['index'] + @headers) @rows.each_with_index do |row, i| arr = ([i + 1] + row) csv << arr end end end |