Sha256: e2aed3df43999437de726de6af0bbe146b9ca29bfcb792267bc3117ddcfc5630

Contents?: true

Size: 622 Bytes

Versions: 1

Compression:

Stored size: 622 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

1 entries across 1 versions & 1 rubygems

Version Path
m3u8-0.7.1 lib/m3u8/time_item.rb