Sha256: f7711b361b786d6f14e07765ecfe7027922ba4d60caabf8d529cdc68aae19ce5

Contents?: true

Size: 592 Bytes

Versions: 10

Compression:

Stored size: 592 Bytes

Contents

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

10 entries across 10 versions & 1 rubygems

Version Path
m3u8-0.7.0 lib/m3u8/time_item.rb
m3u8-0.6.9 lib/m3u8/time_item.rb
m3u8-0.6.8 lib/m3u8/time_item.rb
m3u8-0.6.7 lib/m3u8/time_item.rb
m3u8-0.6.6 lib/m3u8/time_item.rb
m3u8-0.6.5 lib/m3u8/time_item.rb
m3u8-0.6.4 lib/m3u8/time_item.rb
m3u8-0.6.3 lib/m3u8/time_item.rb
m3u8-0.6.2 lib/m3u8/time_item.rb
m3u8-0.6.1 lib/m3u8/time_item.rb