Class: VTTFile

Inherits:
Object
  • Object
show all
Defined in:
lib/vtt2ass/VTTFile.rb

Overview

This class defines a VTT subtile file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ VTTFile

Creates a new VTTFile instance and assigns the default values of instance variables.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vtt2ass/VTTFile.rb', line 14

def initialize(file_path)
    @title = File.basename(file_path).gsub('.vtt', '')
    @lines = []
    separator = OS.posix? ? "\r\n\r\n": "\n\n"
    File.foreach(file_path, separator) do |paragraph|
        paragraph = paragraph.rstrip.gsub(/\r\n/, "\n")
        if not paragraph.eql? "" then
            @lines.push(VTTLine.new(paragraph))
        end
    end
    @lines.shift
end

Instance Attribute Details

#linesObject

Returns the value of attribute lines.



10
11
12
# File 'lib/vtt2ass/VTTFile.rb', line 10

def lines
  @lines
end

Instance Method Details

#to_sObject

This method concatenates the object data in the right order for a string output.



38
39
40
# File 'lib/vtt2ass/VTTFile.rb', line 38

def to_s
    return "WEBVTT\n\n\n" + @lines 
end

#writeToFile(file_path) ⇒ Object

This method writes the content of the VTTFile object into a file path that is provided.



29
30
31
32
33
34
# File 'lib/vtt2ass/VTTFile.rb', line 29

def writeToFile(file_path)
    File.open(file_path, 'w') do |line|
        line.print "\ufeff"
        line.puts self.to_s
    end
end