Skip to content

Commit

Permalink
Extracted new row formatting check
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasdrga committed Sep 22, 2023
1 parent 8a54df8 commit 32ae261
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 8 additions & 4 deletions app/jobs/upvs/fetch_services_with_forms_list_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ def each_row_as_attributes(csv_file, csv_options)
row = row.transform_values { |value| value&.gsub(/[\\"]/,'') }
row = row.transform_values { |v| v == 'NULL' ? nil : v }

row.keys.first&.split(',').each_with_index do |key, index|
row[key] = row.values.first&.split(',')[index]&.gsub(/[\\"]/,'')
end
row.delete(row.keys.first) if row.keys.first&.include?(',')
check_for_row_formatting(row)

yield(
instance_id: row.fetch('IdServiceInstance'),
Expand All @@ -66,4 +63,11 @@ def each_row_as_attributes(csv_file, csv_options)
)
end
end

def check_for_row_formatting(row)
row.keys.first&.split(',').each_with_index do |key, index|
row[key] = row.values.first&.split(',')[index]&.gsub(/[\\"]/,'')
end
row.delete(row.keys.first) if row.keys.first&.include?(',')
end
end
3 changes: 2 additions & 1 deletion db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11001,6 +11001,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20220902164827'),
('20220919080112'),
('20220919084308'),
('20221219105855');
('20221219105855'),
('20230919065811');


0 comments on commit 32ae261

Please sign in to comment.