Skip to content

Commit

Permalink
Use map instead of collect
Browse files Browse the repository at this point in the history
  • Loading branch information
codez committed Sep 21, 2020
1 parent 161e386 commit 47ab25b
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion app/controllers/audio_files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AudioFilesController < ListController
'{playback_format}.{format}' do
operation :get do
key :description, 'Returns an audio file in the requested format.'
key :produces, AudioEncoding.list.collect(&:mime_type).sort
key :produces, AudioEncoding.list.map(&:mime_type).sort
key :tags, [:audio_file, :public]

parameter name: :year,
Expand Down
2 changes: 1 addition & 1 deletion app/models/archive_format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def priviledged_groups=(value)
end

def priviledged_group_list
priviledged_groups.to_s.split(/[,;]/).collect(&:strip).compact
priviledged_groups.to_s.split(/[,;]/).map(&:strip).compact
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def reset_api_key_expires_at
private

def listify(string)
string.to_s.split(/[,;]/).collect(&:strip).compact
string.to_s.split(/[,;]/).map(&:strip).compact
end

end
2 changes: 1 addition & 1 deletion app/services/audio_processor/ffmpeg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def preserving_transcode(new_path, options = {})
end

def create_list_file(file, paths)
entries = paths.collect { |p| "file '#{p}'" }
entries = paths.map { |p| "file '#{p}'" }
File.write(file, entries.join("\n"))
end

Expand Down
8 changes: 4 additions & 4 deletions app/services/import/archiver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ def create_archive_files
end

def build_audio_files
audio_formats.collect do |audio_format|
audio_formats.map do |audio_format|
build_audio_file(audio_format).tap do |file|
link_to_playback_format(file)
end
end
end

def audio_formats
(archive_audio_formats + playback_formats.collect(&:audio_format)).uniq
(archive_audio_formats + playback_formats.map(&:audio_format)).uniq
end

def build_audio_file(format)
Expand Down Expand Up @@ -77,14 +77,14 @@ def archive_audio_formats
end

def actual_archive_audio_formats
mapping.profile.archive_formats.collect(&:audio_format)
mapping.profile.archive_formats.map(&:audio_format)
end

def limited_archive_audio_formats
processor = AudioProcessor.new(master)
actual_archive_audio_formats
.reject { |f| f.encoding.lossless? }
.collect { |f| limited_audio_format(f, processor.bitrate, processor.channels) }
.map { |f| limited_audio_format(f, processor.bitrate, processor.channels) }
end

def limited_audio_format(source, bitrate, channels)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AirtimeDb < Base
private

def build_mappings
show_instances.collect do |instance|
show_instances.map do |instance|
build_broadcast_mapping(instance)
end
end
Expand Down
8 changes: 4 additions & 4 deletions app/services/import/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def mapping_complete?
unless complete
inform("Broadcast #{mapping} is not imported, " \
"as the following recordings do not cover the entire duration:\n" +
mapping.recordings.collect(&:path).join("\n"))
mapping.recordings.map(&:path).join("\n"))
end
end
end
Expand All @@ -66,7 +66,7 @@ def broadcast_valid?
broadcast = mapping.broadcast
broadcast.valid?.tap do |valid|
unless valid
error("Broadcast of #{broadcast.show} @ #{I18n.l(broadcast.started_at)} is invalid: " \
error("Broadcast #{mapping} is invalid: " \
"#{broadcast.errors.full_messages.join(', ')}")
ExceptionNotifier.notify_exception(ActiveRecord::RecordInvalid.new(broadcast),
data: { mapping: mapping })
Expand All @@ -81,7 +81,7 @@ def determine_best_recordings
def compose_master(recordings)
warn_for_too_short_recordings(recordings)
inform("Composing master file for broadcast #{mapping} out of the following recordings:\n" +
recordings.collect(&:path).join("\n"))
recordings.map(&:path).join("\n"))
Recording::Composer.new(mapping, recordings).compose
end

Expand All @@ -97,7 +97,7 @@ def mark_recordings_as_imported
def warn_for_too_short_recordings(recordings)
recordings.select(&:audio_duration_too_short?).each do |r|
exception = Recording::TooShortError.new(r)
error(exception.message)
warn(exception.message)
ExceptionNotifier.notify_exception(exception, data: { mapping: mapping })
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/import/recording/composer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def concat(list)

def with_same_format(list)
unified = convert_all_to_same_format(list)
yield unified.collect(&:path)
yield unified.map(&:path)
ensure
unified&.each { |file| file.close! if file.respond_to?(:close!) }
end
Expand Down
2 changes: 1 addition & 1 deletion db/seeds/broadcast_seeder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def create_weekly_broadcasts(broadcasts, monday)
end

def parse_broadcasts
load_broadcasts.collect do |day, start, finish, name|
load_broadcasts.map do |day, start, finish, name|
start_offset = make_time(day, start)
finish_offset = make_time(day, finish)
finish_offset += 1.day if finish_offset < start_offset
Expand Down
20 changes: 10 additions & 10 deletions test/services/import/broadcast_mapping/builder/airtime_db_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@ class Import::BroadcastMapping::Builder::AirtimeDbTest < ActiveSupport::TestCase
assert_not morgen_map.complete?
assert_equal [file('2016-01-01T090000+0100_060.mp3'),
file('2016-01-01T100000+0100_060.mp3')],
morgen_map.recordings.collect(&:path)
morgen_map.recordings.map(&:path)

info_map = mappings.second
assert_equal info.name, info_map.show.name
assert_equal Time.zone.local(2016, 1, 1, 11), info_map.broadcast.started_at
assert info_map.complete?
assert_equal [file('2016-01-01T110000+0100_060.mp3')],
info_map.recordings.collect(&:path)
info_map.recordings.map(&:path)

becken_map = mappings.third
assert_equal becken.name, becken_map.show.name
assert_equal Time.zone.local(2016, 1, 1, 11, 30), becken_map.broadcast.started_at
assert_equal Time.zone.local(2016, 1, 1, 13), becken_map.broadcast.finished_at
assert_not becken_map.complete?
assert_equal [file('2016-01-01T110000+0100_060.mp3')],
becken_map.recordings.collect(&:path)
becken_map.recordings.map(&:path)
end

test 'multiple recordings are mapped to overlapping broadcasts' do
Expand Down Expand Up @@ -115,15 +115,15 @@ class Import::BroadcastMapping::Builder::AirtimeDbTest < ActiveSupport::TestCase
file('2016-01-01T093000+0100_060.mp3'),
file('2016-01-01T100000+0100_060.mp3'),
file('2016-01-01T103000+0100_030.mp3')],
morgen_map.recordings.collect(&:path)
morgen_map.recordings.map(&:path)

info_map = mappings.second
assert_equal info.name, info_map.show.name
assert_equal Time.zone.local(2016, 1, 1, 11), info_map.broadcast.started_at
assert info_map.complete?
assert_equal [file('2016-01-01T110000+0100_090.mp3'),
file('2016-01-01T110000+0100_060.mp3')],
info_map.recordings.collect(&:path)
info_map.recordings.map(&:path)

becken_map = mappings.third
assert_equal becken.name, becken_map.show.name
Expand All @@ -132,7 +132,7 @@ class Import::BroadcastMapping::Builder::AirtimeDbTest < ActiveSupport::TestCase
assert_not becken_map.complete?
assert_equal [file('2016-01-01T110000+0100_090.mp3'),
file('2016-01-01T110000+0100_060.mp3')],
becken_map.recordings.collect(&:path)
becken_map.recordings.map(&:path)
end

test 'recordings are mapped to adjacent broadcasts' do
Expand Down Expand Up @@ -166,15 +166,15 @@ class Import::BroadcastMapping::Builder::AirtimeDbTest < ActiveSupport::TestCase
assert_equal [file('2016-01-01T080000+0100_060.mp3'),
file('2016-01-01T090000+0100_060.mp3'),
file('2016-01-01T100000+0100_060.mp3')],
map8.recordings.collect(&:path)
map8.recordings.map(&:path)

map10 = mappings.second
assert_equal morgen.name, map8.show.name
assert_equal Time.zone.local(2016, 1, 1, 10, 30), map10.broadcast.started_at
assert_equal Time.zone.local(2016, 1, 1, 11), map10.broadcast.finished_at
assert map10.complete?
assert_equal [file('2016-01-01T100000+0100_060.mp3')],
map10.recordings.collect(&:path)
map10.recordings.map(&:path)
end

test 'recording is mapped to single broadcasts' do
Expand All @@ -201,7 +201,7 @@ class Import::BroadcastMapping::Builder::AirtimeDbTest < ActiveSupport::TestCase
assert_equal Time.zone.local(2016, 1, 1, 10), map.broadcast.finished_at
assert map.complete?
assert_equal [file('2016-01-01T090000+0100_060.mp3')],
map.recordings.collect(&:path)
map.recordings.map(&:path)
end

test 'logs warnings for unmapped recordings' do
Expand Down Expand Up @@ -291,7 +291,7 @@ def new_builder(recordings)
end

def build_recordings(*names)
names.collect { |f| Import::Recording::File.new(file(f)) }
names.map { |f| Import::Recording::File.new(file(f)) }
end

end
2 changes: 1 addition & 1 deletion test/services/import/recording/composer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ class Import::Recording::ComposerTest < ActiveSupport::TestCase

def build_composer(*recordings)
assign_broadcast
recordings.collect! { |r| Import::Recording::File.new(r) }
recordings.map! { |r| Import::Recording::File.new(r) }
recordings.each { |r| mapping.add_recording_if_overlapping(r) }
Import::Recording::Composer.new(mapping, recordings)
end
Expand Down
4 changes: 2 additions & 2 deletions test/services/import/recording/finder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ class Import::Recording::FinderTest < ActiveSupport::TestCase
file('2016-01-02T000000-1200_PT1H.flac'),
file('2016-01-04T000000-1200_PT45M2.33S.flac'),
file('2015-12-31T000000-1200_030.flac')].sort,
finder.pending.collect(&:path).sort
finder.pending.map(&:path).sort
end

test '#imported includes only imported files' do
assert_equal [file('2016-01-03T000000-1200_PT120M_imported.flac'),
file('2015-12-31T000000-1200_030_imported.mp3')].sort,
finder.imported.collect(&:path).sort
finder.imported.map(&:path).sort
end

private
Expand Down
2 changes: 1 addition & 1 deletion test/support/json_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def json
end

def json_attrs(attr)
json['data'].collect { |s| s['attributes'][attr.to_s] }
json['data'].map { |s| s['attributes'][attr.to_s] }
end

end

0 comments on commit 47ab25b

Please sign in to comment.