Class: Application
- Inherits:
-
Object
- Object
- Application
- Defined in:
- lib/vtt2ass/application.rb
Overview
Main application class that manages all the operations.
Instance Method Summary collapse
- #convert(input_path) ⇒ Object
-
#initialize(input, options) ⇒ Application
constructor
Creates a new Application instance.
-
#start ⇒ Object
This method starts the application process.
-
#vtt_to_ass(file_path) ⇒ Object
This method creates a new VTTFile object from the file path provided and convert its content inside a new ASSFile object.
Constructor Details
#initialize(input, options) ⇒ Application
Creates a new Application instance. It receives options that can define the input and output directories.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vtt2ass/application.rb', line 12 def initialize(input, ) @input = input ? input.gsub('\\', '/').delete_suffix('/') : "." @output = [:output] ? [:output].gsub('\\', '/').delete_suffix('/') : nil @width = 1920 @height = 1080 @font_family = [:font_family] ? [:font_family] : 'Open Sans Semibold' @font_size = [:font_size] ? [:font_size] : 52 if [:title] then @title = [:title] end @quiet = [:quiet] if [:css] then @css = [:css].gsub('\\', '/').delete_suffix('/') end @line_offset = [:line_offset] end |
Instance Method Details
#convert(input_path) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/vtt2ass/application.rb', line 45 def convert(input_path) ass_file = vtt_to_ass(input_path) if (not @output.nil?) then ass_file.write_to_file(@output + '/' + File.basename(input_path).gsub('.vtt', '.ass')) end puts ass_file.to_s unless @quiet end |
#start ⇒ Object
This method starts the application process. It sends the file_paths of VTT files in the input directory to convertFileToASS method and outputs the resulting ASS format to a new file.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vtt2ass/application.rb', line 33 def start if File.directory?(@input) then Dir["#{@input}/*.vtt"].each do |file_path| convert(file_path) end elsif File.file?(@input) then convert(@input) else puts 'Error: input file or directory does not exist.' end end |
#vtt_to_ass(file_path) ⇒ Object
This method creates a new VTTFile object from the file path provided and convert its content inside a new ASSFile object.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/vtt2ass/application.rb', line 56 def vtt_to_ass(file_path) base_file_name = File.basename(file_path).gsub('.vtt', '') css_file = nil if defined?(@css) and File.directory?(@css) then css_file = "#{@css}/#{base_file_name}.css" elsif File.file?("#{file_path.gsub('.vtt', '')}.css") then css_file = "#{file_path.gsub('.vtt', '')}.css" else css_file = @css end vtt_file = VTTFile.new(file_path, @width, @height) ass_file = ASSFile.new( (defined?(@title) ? @title : base_file_name), @width, @height, css_file ) ass_file.convert_vtt_to_ass(vtt_file, @font_family, @font_size, @line_offset) return ass_file end |