Method: Bulkrax::CsvParser#write_files

Defined in:
app/parsers/bulkrax/csv_parser.rb

#write_filesObject

export methods



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'app/parsers/bulkrax/csv_parser.rb', line 219

def write_files
  require 'open-uri'
  folder_count = 0
  # TODO: This is not performant as well; unclear how to address, but lower priority as of
  #       <2023-02-21 Tue>.
  sorted_entries = sort_entries(importerexporter.entries.uniq(&:identifier))
                   .select { |e| valid_entry_types.include?(e.type) }

  group_size = limit.to_i.zero? ? total : limit.to_i
  sorted_entries[0..group_size].in_groups_of(records_split_count, false) do |group|
    folder_count += 1

    CSV.open(setup_export_file(folder_count), "w", headers: export_headers, write_headers: true) do |csv|
      group.each do |entry|
        csv << entry.
        # TODO: This is precarious when we have descendents of Bulkrax::CsvCollectionEntry
        next if importerexporter. || entry.type == 'Bulkrax::CsvCollectionEntry'

        store_files(entry.identifier, folder_count.to_s)
      end
    end
  end
end