Class: SRT::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/srt/line.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Line

Returns a new instance of Line.



14
15
16
17
18
# File 'lib/srt/line.rb', line 14

def initialize(options={})
  options.each do |k,v|
    self.send("#{k}=",v)
  end
end

Instance Attribute Details

#display_coordinatesObject

Returns the value of attribute display_coordinates.



3
4
5
# File 'lib/srt/line.rb', line 3

def display_coordinates
  @display_coordinates
end

#end_timeObject

Returns the value of attribute end_time.



6
7
8
# File 'lib/srt/line.rb', line 6

def end_time
  @end_time
end

#errorObject

Returns the value of attribute error.



7
8
9
# File 'lib/srt/line.rb', line 7

def error
  @error
end

#sequenceObject

Returns the value of attribute sequence.



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

def sequence
  @sequence
end

#start_timeObject

Returns the value of attribute start_time.



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

def start_time
  @start_time
end

#textObject



10
11
12
# File 'lib/srt/line.rb', line 10

def text
  @text ||= []
end

Instance Method Details

#cloneObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/srt/line.rb', line 20

def clone
  clone = Line.new
  clone.display_coordinates = display_coordinates
  clone.sequence = sequence
  clone.start_time = start_time
  clone.end_time = end_time
  clone.error = error
  clone.text = text.clone
  clone
end

#empty?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/srt/line.rb', line 31

def empty?
  sequence.nil? && start_time.nil? && end_time.nil? && text.empty?
end

#time_str(subframe_separator = ",") ⇒ Object



35
36
37
# File 'lib/srt/line.rb', line 35

def time_str(subframe_separator=",")
  [@start_time, @end_time].map { |t| sprintf("%02d:%02d:%02d#{subframe_separator}%s", t / 3600, (t % 3600) / 60, t % 60, sprintf("%.3f", t)[-3, 3]) }.join(" --> ")
end

#to_s(time_str_function = :time_str) ⇒ Object



43
44
45
46
47
# File 'lib/srt/line.rb', line 43

def to_s(time_str_function=:time_str)
  content = text.empty? ? [''] : text
  coordinates = display_coordinates ? display_coordinates : ""
  [sequence, send(time_str_function) + coordinates, content, ""].flatten.join("\n")
end

#webvtt_time_strObject



39
40
41
# File 'lib/srt/line.rb', line 39

def webvtt_time_str
  time_str(".")
end