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.



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

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



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

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



54
55
56
57
58
# File 'lib/poms/fields/schedule.rb', line 54

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



47
48
49
50
51
# File 'lib/poms/fields/schedule.rb', line 47

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.



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