Skip to content

Instantly share code, notes, and snippets.

@adamrunner
Created June 25, 2020 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamrunner/6ce1c50b00bbf1b592c9d97c59d306f5 to your computer and use it in GitHub Desktop.
Save adamrunner/6ce1c50b00bbf1b592c9d97c59d306f5 to your computer and use it in GitHub Desktop.
generates a CSV file where the first column is category titles in "crumbs" format for BR, second column is category IDs in "crumb_ids" format for BR.
class GenerateCrumbsCsvService
def self.perform
data = []
Category.where(listed: true, depth: 2).each do |category|
crumbs_id = [category.parent.parent._id.to_s, category.parent._id.to_s, category._id.to_s].join("|")
crumbs = [category.parent.parent.title, category.parent.title, category.title].join("|")
data.push([crumbs, crumbs_id])
end
CSV.open("/tmp/crumbs.csv", "w") do |csv|
data.each do |data_row|
csv << data_row
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment