Class: M3u8::BitrateItem

Inherits:
Object
  • Object
show all
Includes:
Serializable
Defined in:
lib/m3u8/bitrate_item.rb

Overview

BitrateItem represents an EXT-X-BITRATE tag that indicates the approximate bitrate of the following media segments in kbps.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Serializable

#as_json, serialize, #to_h, #to_json

Constructor Details

#initialize(params = {}) ⇒ BitrateItem

Returns a new instance of BitrateItem.

Parameters:

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

    attribute key-value pairs



13
14
15
16
17
# File 'lib/m3u8/bitrate_item.rb', line 13

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

Instance Attribute Details

#bitrateInteger?

Returns approximate bitrate in kbps.

Returns:

  • (Integer, nil)

    approximate bitrate in kbps



10
11
12
# File 'lib/m3u8/bitrate_item.rb', line 10

def bitrate
  @bitrate
end

Class Method Details

.parse(text) ⇒ BitrateItem

Parse an EXT-X-BITRATE tag.

Parameters:

  • text (String)

    raw tag line

Returns:



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

def self.parse(text)
  value = text.gsub('#EXT-X-BITRATE:', '').strip
  BitrateItem.new(bitrate: value.to_i)
end

Instance Method Details

#to_sString

Render as an m3u8 EXT-X-BITRATE tag.

Returns:

  • (String)


29
30
31
# File 'lib/m3u8/bitrate_item.rb', line 29

def to_s
  "#EXT-X-BITRATE:#{bitrate}"
end