Class: M3u8::DefineItem

Inherits:
Object
  • Object
show all
Extended by:
M3u8
Includes:
Serializable
Defined in:
lib/m3u8/define_item.rb

Overview

DefineItem represents an EXT-X-DEFINE tag which provides variable definitions for variable substitution. Supports three mutually exclusive modes: NAME/VALUE, IMPORT, or QUERYPARAM.

Constant Summary

Constants included from M3u8

VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from M3u8

initialize_with_byterange, parse_attributes, parse_float, parse_int, parse_yes_no, to_yes_no

Methods included from Serializable

#as_json, serialize, #to_h, #to_json

Constructor Details

#initialize(params = {}) ⇒ DefineItem

Returns a new instance of DefineItem.

Parameters:

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

    attribute key-value pairs



18
19
20
21
22
# File 'lib/m3u8/define_item.rb', line 18

def initialize(params = {})
  params.each do |key, val|
    instance_variable_set("@#{key}", val)
  end
end

Instance Attribute Details

#importString?

Returns:

  • (String, nil)

    variable name

  • (String, nil)

    variable value

  • (String, nil)

    imported variable name

  • (String, nil)

    query parameter name



15
16
17
# File 'lib/m3u8/define_item.rb', line 15

def import
  @import
end

#nameString?

Returns:

  • (String, nil)

    variable name

  • (String, nil)

    variable value

  • (String, nil)

    imported variable name

  • (String, nil)

    query parameter name



15
16
17
# File 'lib/m3u8/define_item.rb', line 15

def name
  @name
end

#queryparamString?

Returns:

  • (String, nil)

    variable name

  • (String, nil)

    variable value

  • (String, nil)

    imported variable name

  • (String, nil)

    query parameter name



15
16
17
# File 'lib/m3u8/define_item.rb', line 15

def queryparam
  @queryparam
end

#valueString?

Returns:

  • (String, nil)

    variable name

  • (String, nil)

    variable value

  • (String, nil)

    imported variable name

  • (String, nil)

    query parameter name



15
16
17
# File 'lib/m3u8/define_item.rb', line 15

def value
  @value
end

Class Method Details

.parse(text) ⇒ DefineItem

Parse an EXT-X-DEFINE tag.

Parameters:

  • text (String)

    raw tag line

Returns:



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

def self.parse(text)
  attributes = parse_attributes(text)
  DefineItem.new(
    name: attributes['NAME'],
    value: attributes['VALUE'],
    import: attributes['IMPORT'],
    queryparam: attributes['QUERYPARAM']
  )
end

Instance Method Details

#to_sString

Render as an m3u8 EXT-X-DEFINE tag.

Returns:

  • (String)


39
40
41
# File 'lib/m3u8/define_item.rb', line 39

def to_s
  "#EXT-X-DEFINE:#{formatted_attributes}"
end