Skip to content

Commit

Permalink
add task to normalize the tracks' names
Browse files Browse the repository at this point in the history
  • Loading branch information
AEtherC0r3 committed Jun 27, 2017
1 parent a5a2670 commit e88c26b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/tasks/normalize_tracks_names.rake
@@ -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

0 comments on commit e88c26b

Please sign in to comment.