11# frozen_string_literal: true
22class CsvExportsController < ApplicationController
33 class RunSignupsFilenameFinder
4- PRIORITIZED_FILENAME_GENERATORS = [
5- -> ( run ) { run . event . title } ,
6- -> ( run ) { "#{ run . event . title } (#{ run . title_suffix } )" } ,
7- -> ( run ) { "#{ run . event . title } (#{ format_run_start_day ( run ) } )" } ,
8- -> ( run ) { "#{ run . event . title } (#{ format_run_start_time ( run ) } )" } ,
9- -> ( run ) { "#{ run . event . title } (#{ format_run_rooms ( run ) } )" } ,
10- -> ( run ) { "#{ run . event . title } (#{ format_run_start_day ( run ) } in #{ format_run_rooms ( run ) } )" } ,
11- -> ( run ) { "#{ run . event . title } (#{ format_run_start_time ( run ) } in #{ format_run_rooms ( run ) } )" } ,
12- -> ( run ) { "#{ run . event . title } (run #{ run . id } )" }
13- ] . freeze
14-
154 def format_run_start_day ( run )
165 run . starts_at . strftime ( "%a" )
176 end
@@ -28,13 +17,28 @@ def format_run_rooms(run)
2817 # strategies
2918 def unique_filename ( event , run , suffix )
3019 filename_generator =
31- PRIORITIZED_FILENAME_GENERATORS . find do |generator |
20+ filename_generators . find do |generator |
3221 filenames = event . runs . map { |r | generator . call ( r ) }
3322 filenames . uniq . size == filenames . size
3423 end
3524
3625 "#{ filename_generator . call ( run ) } #{ suffix } "
3726 end
27+
28+ private
29+
30+ def filename_generators # rubocop:disable Metrics/AbcSize
31+ [
32+ -> ( r ) { r . event . title } ,
33+ -> ( r ) { "#{ r . event . title } (#{ r . title_suffix } )" } ,
34+ -> ( r ) { "#{ r . event . title } (#{ format_run_start_day ( r ) } )" } ,
35+ -> ( r ) { "#{ r . event . title } (#{ format_run_start_time ( r ) } )" } ,
36+ -> ( r ) { "#{ r . event . title } (#{ format_run_rooms ( r ) } )" } ,
37+ -> ( r ) { "#{ r . event . title } (#{ format_run_start_day ( r ) } in #{ format_run_rooms ( r ) } )" } ,
38+ -> ( r ) { "#{ r . event . title } (#{ format_run_start_time ( r ) } in #{ format_run_rooms ( r ) } )" } ,
39+ -> ( r ) { "#{ r . event . title } (run #{ r . id } )" }
40+ ]
41+ end
3842 end
3943
4044 include SendCsv
0 commit comments