Class: M3u8::VariableResolver

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

Overview

VariableResolver applies EXT-X-DEFINE variable substitution to a playlist, replacing $NAME references in URIs and string attribute values with their defined values per RFC 8216bis section 4.2. A definition must appear before any reference that uses it.

Constant Summary collapse

VARIABLE_REFERENCE =
/\{\$([a-zA-Z0-9_-]+)\}/

Instance Method Summary collapse

Constructor Details

#initialize(playlist, imported: {}, query: {}) ⇒ VariableResolver

Returns a new instance of VariableResolver.

Parameters:

  • playlist (Playlist)

    playlist to resolve

  • imported (Hash) (defaults to: {})

    values for IMPORT definitions

  • query (Hash) (defaults to: {})

    values for QUERYPARAM definitions



14
15
16
17
18
# File 'lib/m3u8/variable_resolver.rb', line 14

def initialize(playlist, imported: {}, query: {})
  @playlist = playlist
  @imported = imported
  @query = query
end

Instance Method Details

#resolvePlaylist

Resolve variable references into a new Playlist.

Returns:



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

def resolve
  hash = @playlist.to_h
  hash[:items] = resolve_items(hash[:items])
  Playlist.from_h(hash)
end