class VTTFile
This class defines a VTT subtile file.
Attributes
lines[RW]
Public Class Methods
new(file_path, width, height)
click to toggle source
Creates a new VTTFile
instance and assigns the default values of instance variables.
# File lib/vtt2ass/VTTFile.rb, line 11 def initialize(file_path, width, height) @title = File.basename(file_path).gsub('.vtt', '') @lines = [] separator = determine_line_ending(file_path) ? "\n\n" : "\r\n\r\n" count = 0 File.foreach(file_path, separator) do |paragraph| paragraph = paragraph.rstrip.gsub(/[\r\n]/, "\n") if not paragraph.eql? "" then vtt_line = VTTLine.new(paragraph, width, height) @lines.push(vtt_line) count += 1 end end @lines.shift end
Public Instance Methods
determine_line_ending(file_path)
click to toggle source
# File lib/vtt2ass/VTTFile.rb, line 27 def determine_line_ending(file_path) File.open(file_path, 'r') do |file| return file.readline[/\r?\n$/] == "\n" end end
to_s()
click to toggle source
This method concatenates the object data in the right order for a string output.
# File lib/vtt2ass/VTTFile.rb, line 44 def to_s return "WEBVTT\n\n\n" + @lines end
writeToFile(file_path)
click to toggle source
This method writes the content of the VTTFile
object into a file path that is provided.
# File lib/vtt2ass/VTTFile.rb, line 35 def writeToFile(file_path) File.open(file_path, 'w') do |line| line.print "\ufeff" line.puts self.to_s end end