Class: M3u8::ByteRange

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

Overview

ByteRange represents sub range of a resource

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 = {}) ⇒ ByteRange

Returns a new instance of ByteRange.

Parameters:

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

    :length and optional :start



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

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

Instance Attribute Details

#lengthInteger?

Returns:

  • (Integer, nil)

    number of bytes

  • (Integer, nil)

    start offset in bytes



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

def length
  @length
end

#startInteger?

Returns:

  • (Integer, nil)

    number of bytes

  • (Integer, nil)

    start offset in bytes



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

def start
  @start
end

Class Method Details

.parse(text) ⇒ ByteRange

Parse a byte range string (e.g. “4500@600”).

Parameters:

  • text (String)

    byte range string

Returns:



22
23
24
25
26
27
28
# File 'lib/m3u8/byte_range.rb', line 22

def self.parse(text)
  values = text.split('@')
  length_value = values[0].to_i
  start_value = values[1].to_i unless values[1].nil?
  options = { length: length_value, start: start_value }
  ByteRange.new(options)
end

Instance Method Details

#to_sString

Render as a byte range string (e.g. “4500@600”).

Returns:

  • (String)


32
33
34
# File 'lib/m3u8/byte_range.rb', line 32

def to_s
  "#{length}#{start_format}"
end