Class: Voot::Vtt

Inherits:
Object
  • Object
show all
Defined in:
lib/voot/vtt.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Vtt

Returns a new instance of Vtt.



8
9
10
11
# File 'lib/voot/vtt.rb', line 8

def initialize(options = {})
  @path = options.fetch(:path)
  @header = options[:header]
end

Instance Attribute Details

#headerObject

Returns the value of attribute header.



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

def header
  @header
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#cuesObject



13
14
15
# File 'lib/voot/vtt.rb', line 13

def cues
  @cues ||= Voot::CueList.new
end

#has_header?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/voot/vtt.rb', line 25

def has_header?
  !header.nil? && header.length > 0
end

#saveObject



29
30
31
32
# File 'lib/voot/vtt.rb', line 29

def save
  ensure_destination_directory
  File.open(path, "w") { |destination| destination.write(to_webvtt) }
end

#to_webvttObject



17
18
19
20
21
22
23
# File 'lib/voot/vtt.rb', line 17

def to_webvtt
  if has_header?
    "WEBVTT #{header}\n\n#{cues.to_webvtt}"
  else
    "WEBVTT\n\n#{cues.to_webvtt}"
  end
end