Module: Poms::Fields::Schedule

Extended by:
Schedule
Included in:
Poms::Fields, Schedule
Defined in:
lib/poms/fields/schedule.rb

Overview

modeule to retrieve scheduling/timtable related information from poms items.

Instance Method Summary collapse

Instance Method Details

#available_until(item) ⇒ Object

Returns the enddate of the publication of an internet vod if present.



59
60
61
62
63
64
65
# File 'lib/poms/fields/schedule.rb', line 59

def available_until(item)
  return if item['predictions'].blank?
  internetvod = item['predictions']
    .find { |p| p['platform'] == 'INTERNETVOD' }
  return unless internetvod
  Timestamp.to_datetime(internetvod['publishStop'])
end

#odi_streams(item) ⇒ Object

Returns an array of odi stream types. Note: this code is copied from Broadcast and it is assumed it was working there.



13
14
15
16
17
18
19
20
21
# File 'lib/poms/fields/schedule.rb', line 13

def odi_streams(item)
  locations = item['locations']
  return [] if locations.nil? || locations.empty?
  odi_streams = locations.select { |l| l['programUrl'].match(/^odi/) }
  streams = odi_streams.map do |l|
    l['programUrl'].match(%r{^[\w+]+\:\/\/[\w\.]+\/video\/(\w+)\/\w+})[1]
  end
  streams.uniq
end

#publication(poms_item) ⇒ Object

Returns the first publication from an items location array which has INTERNETVOD and is PUBLISHED



37
38
39
40
41
42
# File 'lib/poms/fields/schedule.rb', line 37

def publication(poms_item)
  return if poms_item['locations'].blank?
  poms_item['locations'].find do |item|
    item['platform'] == 'INTERNETVOD' && item['workflow'] == 'PUBLISHED'
  end
end

#publish_start(poms_item) ⇒ Object

Return the publishStart datetime from a publication



52
53
54
55
56
# File 'lib/poms/fields/schedule.rb', line 52

def publish_start(poms_item)
  published_item = publication(poms_item)
  return unless published_item
  Timestamp.to_datetime(published_item['publishStart'])
end

#publish_stop(poms_item) ⇒ Object

Return the publishStop datetime from a publication



45
46
47
48
49
# File 'lib/poms/fields/schedule.rb', line 45

def publish_stop(poms_item)
  published_item = publication(poms_item)
  return unless published_item
  Timestamp.to_datetime(published_item['publishStop'])
end

#schedule_events(item) ⇒ Object

Returns an array of start and end times for the scheduled events for this item. It returns an empty array if no events are found. You can pass in a block to filter the events on data that is not returned, like channel.

Parameters:

  • item

    The Poms hash



29
30
31
32
33
# File 'lib/poms/fields/schedule.rb', line 29

def schedule_events(item)
  events = item.fetch('scheduleEvents', [])
  events = yield(events) if block_given?
  events.map { |event| hash_event(event) }
end