lib/m3u8/playlist.rb in m3u8-0.6.9 vs lib/m3u8/playlist.rb in m3u8-0.7.0

- old
+ new

@@ -1,11 +1,11 @@ module M3u8 # Playlist represents an m3u8 playlist, it can be a master playlist or a set # of media segments class Playlist attr_accessor :items, :version, :cache, :target, :sequence, :type, - :iframes_only + :iframes_only, :independent_segments def initialize(options = {}) assign_options options self.items = [] end @@ -19,22 +19,22 @@ reader = Reader.new reader.read input end def write(output) - writer = Writer.new output - writer.write self + writer = Writer.new(output) + writer.write(self) end def master? return false if playlist_size == 0 && segment_size == 0 playlist_size > 0 end def to_s output = StringIO.open - write output + write(output) output.string end def valid? return false if playlist_size > 0 && segment_size > 0 @@ -50,23 +50,27 @@ end private def assign_options(options) - options = { - version: 3, - sequence: 0, - cache: true, - target: 10, - iframes_only: false - }.merge options + options = defaults.merge(options) self.version = options[:version] self.sequence = options[:sequence] self.cache = options[:cache] self.target = options[:target] self.type = options[:type] self.iframes_only = options[:iframes_only] + self.independent_segments = options[:independent_segments] + end + + def defaults + { + sequence: 0, + target: 10, + iframes_only: false, + independent_segments: false + } end def playlist_size items.count { |item| item.is_a?(PlaylistItem) } end