Method: Marty::DataGrid#export_array

Defined in:
app/models/marty/data_grid.rb

#export_arrayObject



534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
# File 'app/models/marty/data_grid.rb', line 534

def export_array
  # add data type metadata row if not default
  lenstr = 'lenient' if lenient
  strict_null_mode_str = 'strict_null_mode' if strict_null_mode

  typestr = data_type unless [nil, DEFAULT_DATA_TYPE].member?(data_type)
  len_type = [lenstr, strict_null_mode_str, typestr].compact.join(' ')

  meta_rows = if len_type.present? || constraint.present?
                [[len_type, constraint].compact]
              else
                []
              end

  meta_rows += .map do |inf|
    [inf['attr'], inf['type'], inf['dir'], inf['rs_keep'] || '']
  end

  v_infos, h_infos = dir_infos('v'), dir_infos('h')

  h_key_rows = h_infos.map do |inf|
    [nil] * v_infos.count + self.class.export_keys(inf)
  end

  transposed_v_keys = v_infos.empty? ? [[]] :
    v_infos.map { |inf| self.class.export_keys(inf) }.transpose

  data_rows = transposed_v_keys.each_with_index.map do |keys, i|
    keys + (data[i] || [])
  end

  [meta_rows, h_key_rows, data_rows]
end