Sha256: 4cdcc39821894ddedd29892293bfd491538fd8eafaf847d3ae16ac3d3ab823f3

Contents?: true

Size: 1.11 KB

Versions: 14

Compression:

Stored size: 1.11 KB

Contents

module M3u8
  # SessionDataItem represents a set of EXT-X-SESSION-DATA attributes
  class SessionDataItem
    extend M3u8
    attr_accessor :data_id, :value, :uri, :language

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

    def self.parse(text)
      attributes = parse_attributes text
      options = { data_id: attributes['DATA-ID'], value: attributes['VALUE'],
                  uri: attributes['URI'], language: attributes['LANGUAGE'] }
      M3u8::SessionDataItem.new options
    end

    def to_s
      attributes = [data_id_format,
                    value_format,
                    uri_format,
                    language_format].compact.join(',')
      "#EXT-X-SESSION-DATA:#{attributes}"
    end

    private

    def data_id_format
      %(DATA-ID="#{data_id}")
    end

    def value_format
      return if value.nil?

      %(VALUE="#{value}")
    end

    def uri_format
      return if uri.nil?

      %(URI="#{uri}")
    end

    def language_format
      return if language.nil?

      %(LANGUAGE="#{language}")
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
m3u8-0.7.0 lib/m3u8/session_data_item.rb
m3u8-0.6.9 lib/m3u8/session_data_item.rb
m3u8-0.6.8 lib/m3u8/session_data_item.rb
m3u8-0.6.7 lib/m3u8/session_data_item.rb
m3u8-0.6.6 lib/m3u8/session_data_item.rb
m3u8-0.6.5 lib/m3u8/session_data_item.rb
m3u8-0.6.4 lib/m3u8/session_data_item.rb
m3u8-0.6.3 lib/m3u8/session_data_item.rb
m3u8-0.6.2 lib/m3u8/session_data_item.rb
m3u8-0.6.1 lib/m3u8/session_data_item.rb
m3u8-0.5.3 lib/m3u8/session_data_item.rb
m3u8-0.5.2 lib/m3u8/session_data_item.rb
m3u8-0.5.1 lib/m3u8/session_data_item.rb
m3u8-0.5.0 lib/m3u8/session_data_item.rb