app/models/bulkrax/csv_entry.rb in bulkrax-4.3.1 vs app/models/bulkrax/csv_entry.rb in bulkrax-4.4.0

- old
+ new

@@ -16,11 +16,11 @@ # there's a risk that this reads the whole file into memory and could cause a memory leak def self.read_data(path) raise StandardError, 'CSV path empty' if path.blank? CSV.read(path, headers: true, - header_converters: :symbol, + header_converters: ->(h) { h.to_sym }, encoding: 'utf-8') end def self.data_for_entry(data, _source_id, parser) # If a multi-line CSV data is passed, grab the first row @@ -79,11 +79,11 @@ end def add_file self.parsed_metadata['file'] ||= [] if record['file']&.is_a?(String) - self.parsed_metadata['file'] = record['file'].split(/\s*[;|]\s*/) + self.parsed_metadata['file'] = record['file'].split(Bulkrax.multi_value_element_split_on) elsif record['file'].is_a?(Array) self.parsed_metadata['file'] = record['file'] end self.parsed_metadata['file'] = self.parsed_metadata['file'].map do |f| next if f.blank? @@ -174,11 +174,11 @@ def build_value(key, value) data = hyrax_record.send(key.to_s) if data.is_a?(ActiveTriples::Relation) if value['join'] - self.parsed_metadata[key_for_export(key)] = data.map { |d| prepare_export_data(d) }.join(' | ').to_s # TODO: make split char dynamic + self.parsed_metadata[key_for_export(key)] = data.map { |d| prepare_export_data(d) }.join(Bulkrax.multi_value_element_join_on).to_s else data.each_with_index do |d, i| self.parsed_metadata["#{key_for_export(key)}_#{i + 1}"] = prepare_export_data(d) end end @@ -234,11 +234,11 @@ handle_join_on_export(thumbnail_mapping, filenames, false) end def handle_join_on_export(key, values, join) if join - parsed_metadata[key] = values.join(' | ') # TODO: make split char dynamic + parsed_metadata[key] = values.join(Bulkrax.multi_value_element_join_on) else values.each_with_index do |value, i| parsed_metadata["#{key}_#{i + 1}"] = value end parsed_metadata.delete(key) @@ -258,10 +258,10 @@ parent_field_mapping = self.class.parent_field(parser) return [] unless parent_field_mapping.present? && record[parent_field_mapping].present? identifiers = [] - split_references = record[parent_field_mapping].split(/\s*[;|]\s*/) + split_references = record[parent_field_mapping].split(Bulkrax.multi_value_element_split_on) split_references.each do |c_reference| matching_collection_entries = importerexporter.entries.select do |e| (e.raw_metadata&.[](source_identifier) == c_reference) && e.is_a?(CsvCollectionEntry) end