Class: VTTLine

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

Overview

This class defines a VTT subtile line.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paragraph, width, height) ⇒ VTTLine

This method creates an instance of an VTTLine.

  • Requires paragraph, a VTT formatted string as input.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/vtt2ass/vtt_line.rb', line 11

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

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



5
6
7
# File 'lib/vtt2ass/vtt_line.rb', line 5

def params
  @params
end

#styleObject

Returns the value of attribute style.



4
5
6
# File 'lib/vtt2ass/vtt_line.rb', line 4

def style
  @style
end

#textObject (readonly)

Returns the value of attribute text.



5
6
7
# File 'lib/vtt2ass/vtt_line.rb', line 5

def text
  @text
end

#time_endObject (readonly)

Returns the value of attribute time_end.



5
6
7
# File 'lib/vtt2ass/vtt_line.rb', line 5

def time_end
  @time_end
end

#time_startObject (readonly)

Returns the value of attribute time_start.



5
6
7
# File 'lib/vtt2ass/vtt_line.rb', line 5

def time_start
  @time_start
end

Instance Method Details

#to_sObject

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



41
42
43
# File 'lib/vtt2ass/vtt_line.rb', line 41

def to_s
    return "#{@style} \n#{@time_start} --> #{@time_end} #{@params}\n#{@text}"
end