Class: VTTLine
- Inherits:
-
Object
- Object
- VTTLine
- Defined in:
- lib/vtt2ass/vtt_line.rb
Overview
This class defines a VTT subtile line.
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#style ⇒ Object
Returns the value of attribute style.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#time_end ⇒ Object
readonly
Returns the value of attribute time_end.
-
#time_start ⇒ Object
readonly
Returns the value of attribute time_start.
Instance Method Summary collapse
-
#initialize(paragraph, width, height) ⇒ VTTLine
constructor
This method creates an instance of an VTTLine.
-
#to_s ⇒ Object
This method assigns the object values and outputs a VTT dialogue line.
Constructor Details
#initialize(paragraph, width, height) ⇒ VTTLine
This method creates an instance of an VTTLine.
-
Requires
paragraph
, a VTT formatted string as input.
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 13 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 !m && count.zero? @style = line elsif m @time_start = m[1] @time_end = m[2] @params = m[3] ass_style = ASSStyleParams.new(@params, width, height) @style = 'MainTop' if @style.eql?('Main') && ass_style.alignment == 8 else @text += "#{line}\n" end count += 1 end @text = @text.lstrip end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
7 8 9 |
# File 'lib/vtt2ass/vtt_line.rb', line 7 def params @params end |
#style ⇒ Object
Returns the value of attribute style.
6 7 8 |
# File 'lib/vtt2ass/vtt_line.rb', line 6 def style @style end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
7 8 9 |
# File 'lib/vtt2ass/vtt_line.rb', line 7 def text @text end |
#time_end ⇒ Object (readonly)
Returns the value of attribute time_end.
7 8 9 |
# File 'lib/vtt2ass/vtt_line.rb', line 7 def time_end @time_end end |
#time_start ⇒ Object (readonly)
Returns the value of attribute time_start.
7 8 9 |
# File 'lib/vtt2ass/vtt_line.rb', line 7 def time_start @time_start end |
Instance Method Details
#to_s ⇒ Object
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 "#{@style} \n#{@time_start} --> #{@time_end} #{@params}\n#{@text}" end |