Skip to content

Instantly share code, notes, and snippets.

@condef5
Created May 26, 2021 20:43
Show Gist options
  • Save condef5/5d86fb92c7f6248d7364dd7e3a63fb71 to your computer and use it in GitHub Desktop.
Save condef5/5d86fb92c7f6248d7364dd7e3a63fb71 to your computer and use it in GitHub Desktop.
require 'roo'
require 'csv'
full_path = ->(f) { File.join('data', f) }
remove_options = %w[(TEST PRACTICE) (Form) (Responses) .xlsx]
format_form_name = ->(form) do
form.gsub(Regexp.union(remove_options), '')
end
paths = Dir.entries('data').select { |f| File.file? full_path.call(f) }
fields = paths.map do |f|
data = Roo::Spreadsheet.open(full_path.call(f))
data.row(1)
end
headers = fields.flatten.uniq
CSV.open('result.csv', 'w') do |csv|
csv << ['Form name', *headers]
# fields
fields.each_with_index do |form_fields, index|
form_name = format_form_name.call(paths[index])
checks_fields = headers.map do |column|
form_fields.include?(column) ? '✅' : nil
end
csv << [form_name, *checks_fields]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment