Sha256: 7ff35f78fc8ebc40826ad082130225c9cc14a1533bd63ca299709d48d623b84f

Contents?: true

Size: 623 Bytes

Versions: 3

Compression:

Stored size: 623 Bytes

Contents

# frozen_string_literal: true
module M3u8
  # TimeItem represents EXT-X-PROGRAM-DATE-TIME
  class TimeItem
    extend M3u8
    attr_accessor :time

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

    def self.parse(text)
      time = text.gsub('#EXT-X-PROGRAM-DATE-TIME:', '')
      options = { time: Time.parse(time) }
      TimeItem.new(options)
    end

    def to_s
      %(#EXT-X-PROGRAM-DATE-TIME:#{time_format})
    end

    private

    def time_format
      return time if time.is_a?(String)
      time.iso8601
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
m3u8-0.8.2 lib/m3u8/time_item.rb
m3u8-0.8.1 lib/m3u8/time_item.rb
m3u8-0.8.0 lib/m3u8/time_item.rb