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.



65
66
67
68
69
70
71
72
73
# File 'lib/poms/fields/schedule.rb', line 65

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
22
# 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 and does not have owner NEBO.



38
39
40
41
42
43
44
45
46
# File 'lib/poms/fields/schedule.rb', line 38

def publication(poms_item)
  return if poms_item.fetch('locations', nil).blank?

  poms_item.fetch('locations', []).find do |item|
    item.fetch('platform', '') == 'INTERNETVOD' &&
      item.fetch('workflow', '') == 'PUBLISHED' &&
      item.fetch('owner', '') != 'NEBO'
  end
end

#publish_start(poms_item) ⇒ Object

Return the publishStart datetime from a publication



57
58
59
60
61
62
# File 'lib/poms/fields/schedule.rb', line 57

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



49
50
51
52
53
54
# File 'lib/poms/fields/schedule.rb', line 49

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



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

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