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_float, parse_yes_no

Constructor Details

#initialize(params = {}) ⇒ MediaItem

Returns a new instance of MediaItem.



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

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.



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

def assoc_language
  @assoc_language
end

#autoselectObject

Returns the value of attribute autoselect.



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

def autoselect
  @autoselect
end

#defaultObject

Returns the value of attribute default.



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

def default
  @default
end

#forcedObject

Returns the value of attribute forced.



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

def forced
  @forced
end

#group_idObject

Returns the value of attribute group_id.



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

def group_id
  @group_id
end

#languageObject

Returns the value of attribute language.



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

def language
  @language
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

#uriObject

Returns the value of attribute uri.



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

def uri
  @uri
end

Class Method Details

.parse(text) ⇒ Object



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

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



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

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