Class: Appydave::Tools::SubtitleMaster::Clean

Inherits:
Object
  • Object
show all
Defined in:
lib/appydave/tools/subtitle_manager/clean.rb

Overview

Clean and normalize subtitles

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path: nil, srt_content: nil) ⇒ Clean

Returns a new instance of Clean.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/appydave/tools/subtitle_manager/clean.rb', line 10

def initialize(file_path: nil, srt_content: nil)
  if file_path && srt_content
    raise ArgumentError, 'You cannot provide both a file path and an SRT content stream.'
  elsif file_path.nil? && srt_content.nil?
    raise ArgumentError, 'You must provide either a file path or an SRT content stream.'
  end

  @content = if file_path
               File.read(file_path, encoding: 'UTF-8')
             else
               srt_content
             end
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



8
9
10
# File 'lib/appydave/tools/subtitle_manager/clean.rb', line 8

def content
  @content
end

Instance Method Details

#cleanObject



24
25
26
27
# File 'lib/appydave/tools/subtitle_manager/clean.rb', line 24

def clean
  content = remove_underscores(@content)
  normalize_lines(content)
end

#write(output_file) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/appydave/tools/subtitle_manager/clean.rb', line 29

def write(output_file)
  File.write(output_file, content)
  puts "Processed file written to #{output_file}"
rescue Errno::EACCES
  puts "Permission denied: Unable to write to #{output_file}"
rescue StandardError => e
  puts "An error occurred while writing to the file: #{e.message}"
end