class VTTLine

This class defines a VTT subtile line.

Attributes

params[R]
style[R]
text[R]
time_end[R]
time_start[R]

Public Class Methods

new(paragraph, width, height) click to toggle source

This method creates an instance of an VTTLine.

  • Requires paragraph, a VTT formatted string as input.

# File lib/vtt2ass/VTTLine.rb, line 10
def initialize(paragraph, width, height)
    lines = paragraph.split("\n")
    rx = /^([\d:.]*) --> ([\d:.]*)\s?(.*?)\s*$/
    @style = "Main"
    @text, @time_start, @time_end, @params = ""
    count = 0

    lines.each do |line|
        m = line.match(rx)
        if not m and count == 0 then
            @style = line
        elsif m then
            @time_start = m[1]
            @time_end = m[2]
            @params = m[3]
            ass_style = ASSStyleParams.new(@params, width, height)
            if @style.eql? 'Main' and ass_style.alignment == 8 then
                @style = "MainTop"
            end
        else
            @text += line + "\n"
        end
        count += 1;
    end

    @text = @text.lstrip
end

Public Instance Methods

to_s() click to toggle source

This method assigns the object values and outputs a VTT dialogue line.

# File lib/vtt2ass/VTTLine.rb, line 40
def to_s
    return "#{@style} \n#{@time_start} --> #{@time_end} #{@params}\n#{@text}"
end