class M3u8::DateRangeItem

DateRangeItem represents a #EXT-X-DATERANGE tag

Attributes

class_name[RW]
client_attributes[RW]
duration[RW]
end_date[RW]
end_on_next[RW]
id[RW]
planned_duration[RW]
scte35_cmd[RW]
scte35_in[RW]
scte35_out[RW]
start_date[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/m3u8/date_range_item.rb, line 10
def initialize(options = {})
  options.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Public Instance Methods

parse(text) click to toggle source
# File lib/m3u8/date_range_item.rb, line 16
def parse(text)
  attributes = parse_attributes(text)
  @id = attributes['ID']
  @class_name = attributes['CLASS']
  @start_date = attributes['START-DATE']
  @end_date = attributes['END-DATE']
  @duration = parse_float(attributes['DURATION'])
  @planned_duration = parse_float(attributes['PLANNED-DURATION'])
  @scte35_cmd = attributes['SCTE35-CMD']
  @scte35_out = attributes['SCTE35-OUT']
  @scte35_in = attributes['SCTE35-IN']
  @end_on_next = attributes.key?('END-ON-NEXT') ? true : false
  @client_attributes = parse_client_attributes(attributes)
end
to_s() click to toggle source
# File lib/m3u8/date_range_item.rb, line 31
def to_s
  "#EXT-X-DATERANGE:#{formatted_attributes}"
end

Private Instance Methods

class_name_format() click to toggle source
# File lib/m3u8/date_range_item.rb, line 51
def class_name_format
  return if class_name.nil?
  %(CLASS="#{class_name}")
end
client_attributes_format() click to toggle source
# File lib/m3u8/date_range_item.rb, line 71
def client_attributes_format
  return if client_attributes.nil?
  client_attributes.map do |attribute|
    value = attribute.last
    value_format = decimal?(value) ? value : %("#{value}")
    "#{attribute.first}=#{value_format}"
  end
end
decimal?(value) click to toggle source
# File lib/m3u8/date_range_item.rb, line 80
def decimal?(value)
  return true if value =~ /\A\d+\Z/
  begin
    return true if Float(value)
  rescue
    false
  end
end
duration_format() click to toggle source
# File lib/m3u8/date_range_item.rb, line 61
def duration_format
  return if duration.nil?
  "DURATION=#{duration}"
end
end_date_format() click to toggle source
# File lib/m3u8/date_range_item.rb, line 56
def end_date_format
  return if end_date.nil?
  %(END-DATE="#{end_date}")
end
end_on_next_format() click to toggle source
# File lib/m3u8/date_range_item.rb, line 104
def end_on_next_format
  return unless end_on_next
  'END-ON-NEXT=YES'
end
formatted_attributes() click to toggle source
# File lib/m3u8/date_range_item.rb, line 37
def formatted_attributes
  [%(ID="#{id}"),
   class_name_format,
   %(START-DATE="#{start_date}"),
   end_date_format,
   duration_format,
   planned_duration_format,
   client_attributes_format,
   scte35_cmd_format,
   scte35_out_format,
   scte35_in_format,
   end_on_next_format].compact.join(',')
end
parse_client_attributes(attributes) click to toggle source
# File lib/m3u8/date_range_item.rb, line 109
def parse_client_attributes(attributes)
  attributes.select { |key| key.start_with?('X-') }
end
planned_duration_format() click to toggle source
# File lib/m3u8/date_range_item.rb, line 66
def planned_duration_format
  return if planned_duration.nil?
  "PLANNED-DURATION=#{planned_duration}"
end
scte35_cmd_format() click to toggle source
# File lib/m3u8/date_range_item.rb, line 89
def scte35_cmd_format
  return if scte35_cmd.nil?
  "SCTE35-CMD=#{scte35_cmd}"
end
scte35_in_format() click to toggle source
# File lib/m3u8/date_range_item.rb, line 99
def scte35_in_format
  return if scte35_in.nil?
  "SCTE35-IN=#{scte35_in}"
end
scte35_out_format() click to toggle source
# File lib/m3u8/date_range_item.rb, line 94
def scte35_out_format
  return if scte35_out.nil?
  "SCTE35-OUT=#{scte35_out}"
end