Class: VTTSubtitle
- Inherits:
-
Object
- Object
- VTTSubtitle
- Defined in:
- lib/vtt2ass/VTTSubtitle.rb
Overview
This class defines a VTT subtile line.
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#style ⇒ Object
readonly
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) ⇒ VTTSubtitle
constructor
This method creates an instance of an VTTSubtitle.
-
#to_s ⇒ Object
This method assigns the object values and outputs a VTT dialogue line.
Constructor Details
#initialize(paragraph) ⇒ VTTSubtitle
This method creates an instance of an VTTSubtitle.
-
Requires
paragraph
, a VTT formatted string as input.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vtt2ass/VTTSubtitle.rb', line 10 def initialize(paragraph) 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] if @params.include? "align:middle line:7%" then @style = "MainTop" end else @text += line + "\n" end count += 1; end end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
4 5 6 |
# File 'lib/vtt2ass/VTTSubtitle.rb', line 4 def params @params end |
#style ⇒ Object (readonly)
Returns the value of attribute style.
4 5 6 |
# File 'lib/vtt2ass/VTTSubtitle.rb', line 4 def style @style end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
4 5 6 |
# File 'lib/vtt2ass/VTTSubtitle.rb', line 4 def text @text end |
#time_end ⇒ Object (readonly)
Returns the value of attribute time_end.
4 5 6 |
# File 'lib/vtt2ass/VTTSubtitle.rb', line 4 def time_end @time_end end |
#time_start ⇒ Object (readonly)
Returns the value of attribute time_start.
4 5 6 |
# File 'lib/vtt2ass/VTTSubtitle.rb', line 4 def time_start @time_start end |
Instance Method Details
#to_s ⇒ Object
This method assigns the object values and outputs a VTT dialogue line.
37 38 39 |
# File 'lib/vtt2ass/VTTSubtitle.rb', line 37 def to_s return "#{@style} \n#{@time_start} --> #{@time_end} #{@params}\n#{@text}" end |