Skip to content

Commit

Permalink
Merge pull request #5931 from avalonmediasystem/cast_to_boolean
Browse files Browse the repository at this point in the history
Cast treat as transcript and machine generated field to boolean
  • Loading branch information
masaball authored Jul 12, 2024
2 parents c4bcd87 + 99d0f05 commit 205f2ca
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
4 changes: 4 additions & 0 deletions lib/avalon/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,9 @@ def self.extract_files_from_lsof_output(output)
end
found_files
end

def self.true_field?(value)
not (value.to_s =~ /^(y(es)?|t(rue)?)$/i).nil?
end
end
end
4 changes: 2 additions & 2 deletions lib/avalon/batch/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ def self.process_datastream(datastream, type, parent_id)
filename = datastream[file_key].split('/').last
label = datastream[label_key].presence || filename
language = datastream[language_key].present? ? content_language(datastream[language_key]) : Settings.caption_default.language
treat_as_transcript = datastream[:treat_as_transcript].present? ? 'transcript' : nil
machine_generated = datastream[:machine_generated].present? ? 'machine_generated' : nil
treat_as_transcript = Avalon::Batch.true_field?(datastream[:treat_as_transcript]) ? 'transcript' : nil
machine_generated = Avalon::Batch.true_field?(datastream[:machine_generated]) ? 'machine_generated' : nil
# Create SupplementalFile
supplemental_file = SupplementalFile.new(label: label, tags: [type, treat_as_transcript, machine_generated].uniq.compact, language: language, parent_id: parent_id)
supplemental_file.file.attach(io: FileLocator.new(datastream[file_key]).reader, filename: filename)
Expand Down
7 changes: 2 additions & 5 deletions lib/avalon/batch/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ def delete
end

private
def true?(value)
not (value.to_s =~ /^(y(es)?|t(rue)?)$/i).nil?
end

def supplementing_files(field, content, values, i)
if field.to_s.include?('file')
Expand Down Expand Up @@ -146,7 +143,7 @@ def create_entries!
supplementing_files(f, content, values, i)
next
end
content.last[f] = f == :skip_transcoding ? true?(values[i]) : values[i]
content.last[f] = f == :skip_transcoding ? Avalon::Batch.true_field?(values[i]) : values[i]
else
fields[f] << values[i]
end
Expand All @@ -156,7 +153,7 @@ def create_entries!
opts.keys.each { |opt|
val = Array(fields.delete(opt)).first.to_s
if opts[opt].is_a?(TrueClass) or opts[opt].is_a?(FalseClass)
opts[opt] = true?(val)
opts[opt] = Avalon::Batch.true_field?(val)
else
opts[opt] = val
end
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/avalon/batch/entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@

context 'with multiple captions and transcripts' do
let(:caption) { [{ :caption_file => caption_file, :caption_label => 'Sheephead Captions', :caption_language => 'english', :treat_as_transcript => 'yes' },
{ :caption_file => caption_file, :caption_label => 'Second Caption', :caption_language => 'fre', :machine_generated => 'yes' }] }
let(:transcript) { [{ :transcript_file => caption_file, :transcript_label => 'Sheephead Transcript' },
{ :caption_file => caption_file, :caption_label => 'Second Caption', :caption_language => 'fre', :machine_generated => 'yes', :treat_as_transcript => 'no' }] }
let(:transcript) { [{ :transcript_file => caption_file, :transcript_label => 'Sheephead Transcript', :machine_generated => 'no' },
{ :transcript_file => caption_file, :transcript_language => 'french', :machine_generated => 'yes' }] }
it 'should attach all captions and transcripts to master file' do
expect(master_file.has_captions?).to eq true
Expand Down

0 comments on commit 205f2ca

Please sign in to comment.