Class: M3u8::MediaItem

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

Overview

MediaItem represents a set of EXT-X-MEDIA attributes

Constant Summary

Constants included from M3u8

VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from M3u8

intialize_with_byterange, parse_attributes, parse_yes_no

Constructor Details

#initialize(params = {}) ⇒ MediaItem

Returns a new instance of MediaItem.



8
9
10
11
12
# File 'lib/m3u8/media_item.rb', line 8

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

Instance Attribute Details

#assoc_languageObject

Returns the value of attribute assoc_language.



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

def assoc_language
  @assoc_language
end

#autoselectObject

Returns the value of attribute autoselect.



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

def autoselect
  @autoselect
end

#defaultObject

Returns the value of attribute default.



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

def default
  @default
end

#forcedObject

Returns the value of attribute forced.



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

def forced
  @forced
end

#group_idObject

Returns the value of attribute group_id.



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

def group_id
  @group_id
end

#languageObject

Returns the value of attribute language.



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

def language
  @language
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

#uriObject

Returns the value of attribute uri.



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

def uri
  @uri
end

Class Method Details

.parse(text) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/m3u8/media_item.rb', line 14

def self.parse(text)
  attributes = parse_attributes text
  options = { type: attributes['TYPE'], group_id: attributes['GROUP-ID'],
              language: attributes['LANGUAGE'],
              assoc_language: attributes['ASSOC-LANGUAGE'],
              name: attributes['NAME'],
              autoselect: parse_yes_no(attributes['AUTOSELECT']),
              default: parse_yes_no(attributes['DEFAULT']),
              forced: parse_yes_no(attributes['FORCED']),
              uri: attributes['URI'] }
  MediaItem.new options
end

Instance Method Details

#to_sObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/m3u8/media_item.rb', line 27

def to_s
  attributes = [type_format,
                group_id_format,
                language_format,
                assoc_language_format,
                name_format,
                autoselect_format,
                default_format,
                uri_format,
                forced_format].compact.join(',')
  "#EXT-X-MEDIA:#{attributes}"
end