Class: M3u8::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/m3u8/writer.rb

Overview

Writer provides generation of text output of playlists in m3u8 format

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ Writer

Returns a new instance of Writer.

Parameters:

  • io (IO)

    writable IO object



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

def initialize(io)
  @io = io
end

Instance Attribute Details

#ioIO

Returns output stream.

Returns:

  • (IO)

    output stream



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

def io
  @io
end

Instance Method Details

#write(playlist) ⇒ void

This method returns an undefined value.

Write a playlist to the output stream.

Parameters:

  • playlist (Playlist)

    playlist to write



17
18
19
20
21
22
23
24
25
26
# File 'lib/m3u8/writer.rb', line 17

def write(playlist)
  validate(playlist)
  write_header(playlist)

  playlist.items.each do |item|
    io.puts item.to_s
  end

  write_footer(playlist)
end


28
29
30
31
32
# File 'lib/m3u8/writer.rb', line 28

def write_footer(playlist)
  return if playlist.live? || playlist.master?

  io.puts '#EXT-X-ENDLIST'
end

#write_header(playlist) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/m3u8/writer.rb', line 34

def write_header(playlist)
  io.puts '#EXTM3U'
  if playlist.master?
    write_master_playlist_header(playlist)
  else
    write_media_playlist_header(playlist)
  end
end