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.



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

def initialize(io)
  @io = io
end

Instance Attribute Details

#ioObject

Returns the value of attribute io.



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

def io
  @io
end

Instance Method Details

#write(playlist) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/m3u8/writer.rb', line 11

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

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

  write_footer(playlist)
end


22
23
24
25
# File 'lib/m3u8/writer.rb', line 22

def write_footer(playlist)
  return if playlist.live? || playlist.master?
  io.puts '#EXT-X-ENDLIST'
end

#write_header(playlist) ⇒ Object



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

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