Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add task to normalize the tracks' names
- Loading branch information
1 parent
a5a2670
commit e88c26b
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace :data do | ||
desc 'Replace underscores with spaces in tracks\' names and make them unique per program' | ||
task normalize_tracks_names: :environment do | ||
Program.all.each do |program| | ||
next_track_index = {} | ||
program.tracks.each do |track| | ||
track_name = track.name.tr('_', ' ') | ||
if next_track_index[track_name] | ||
track_name += " #{next_track_index[track_name]}" | ||
next_track_index[track_name] += 1 | ||
else | ||
next_track_index[track_name] = 0 | ||
end | ||
unless track.save | ||
puts "Failed to update track #{track.name} (ID #{track.id})" | ||
end | ||
end | ||
end | ||
end | ||
end |