Class: WebVTT::File

Inherits:
Blob
  • Object
show all
Defined in:
lib/webvtt/parser.rb

Instance Attribute Summary collapse

Attributes inherited from Blob

#cues, #header

Instance Method Summary collapse

Methods inherited from Blob

#actual_total_length, #parse, #to_webvtt, #total_length

Constructor Details

#initialize(webvtt_file) ⇒ File



86
87
88
89
90
91
92
93
94
# File 'lib/webvtt/parser.rb', line 86

def initialize(webvtt_file)
  if !::File.exist?(webvtt_file)
    raise InputError, "WebVTT file not found"
  end

  @path = webvtt_file
  @filename = ::File.basename(@path)
  super(::File.read(webvtt_file))
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



84
85
86
# File 'lib/webvtt/parser.rb', line 84

def filename
  @filename
end

#pathObject (readonly)

Returns the value of attribute path.



84
85
86
# File 'lib/webvtt/parser.rb', line 84

def path
  @path
end

Instance Method Details

#save(output = nil) ⇒ Object



96
97
98
99
100
101
102
103
# File 'lib/webvtt/parser.rb', line 96

def save(output=nil)
  output ||= @path.gsub(".srt", ".vtt")

  ::File.open(output, "w") do |f|
    f.write(to_webvtt)
  end
  return output
end