Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎁 remove whitespaces from CSV headers #816

Merged
merged 14 commits into from
Jun 26, 2023
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion app/models/bulkrax/csv_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def self.data_for_entry(data, _source_id, parser)
# If a multi-line CSV data is passed, grab the first row
data = data.first if data.is_a?(CSV::Table)
# model has to be separated so that it doesn't get mistranslated by to_h
raw_data = data.to_h
raw_data = clean_data(data.to_h)
raw_data[:model] = data[:model] if data[:model].present?
# If the collection field mapping is not 'collection', add 'collection' - the parser needs it
# TODO: change to :parents
Expand Down Expand Up @@ -383,6 +383,22 @@ def path_to_file(file)

private

# @api private
#
# This method will remove any white spaces from the keys of the data hash
# @param [Hash] data
# @return [Hash] data with keys that have no white spaces
def self.clean_data(data)
modified_hash = {}

data.each do |key, value|
modified_key = key.to_s.strip
ShanaLMoore marked this conversation as resolved.
Show resolved Hide resolved
modified_hash[modified_key.to_sym] = value
end

modified_hash
end

def map_file_sets(file_sets)
file_sets.map { |fs| filename(fs).to_s if filename(fs).present? }.compact
end
Expand Down