Class: Subconv::WebVtt::Writer
- Inherits:
-
Object
- Object
- Subconv::WebVtt::Writer
- Defined in:
- lib/subconv/webvtt/writer.rb
Overview
WebVTT caption writer
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Writer
constructor
A new instance of Writer.
-
#write(io, captions) ⇒ Object
Write captions to an IO stream captions must be an array of Caption instances.
-
#write_caption(io, caption) ⇒ Object
Write a single Scc::Caption to an IO stream.
Constructor Details
#initialize(options = {}) ⇒ Writer
Returns a new instance of Writer.
15 16 17 |
# File 'lib/subconv/webvtt/writer.rb', line 15 def initialize( = {}) @options = end |
Instance Method Details
#write(io, captions) ⇒ Object
Write captions to an IO stream captions must be an array of Caption instances
21 22 23 24 25 26 27 |
# File 'lib/subconv/webvtt/writer.rb', line 21 def write(io, captions) io.write(FILE_MAGIC + "\n\n") captions.each do |caption| write_caption(io, caption) end end |
#write_caption(io, caption) ⇒ Object
Write a single Scc::Caption to an IO stream
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/subconv/webvtt/writer.rb', line 30 def write_caption(io, caption) settings = settings_to_string(caption_settings(caption)) io.write(format(CUE_FORMAT, start_time: timecode_to_webvtt(caption.timespan.start_time), end_time: timecode_to_webvtt(caption.timespan.end_time), settings: settings) + "\n") text = node_to_webvtt_markup caption.content if @options[:trim_line_whitespace] # Trim leading and trailing whitespace from each line text = text.split("\n").each(&:strip!).join("\n") end io.write "#{text}\n\n" end |