Created
June 25, 2020 18:28
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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