-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
147 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
module Megaphone | ||
class Cuepoint | ||
include Megaphone::Model | ||
|
||
CUEPOINT_TYPES = %i[preroll midroll postroll remove] | ||
|
||
AD_SOURCES = %i[auto promo span] | ||
|
||
CREATE_REQUIRED = %i[cuepoint_type ad_count start_time end_time ad_sources action] | ||
|
||
CREATE_ATTRIBUTES = CREATE_REQUIRED + %i[title end_time is_active offset notes] | ||
|
||
ALL_ATTRIBUTES = (CREATE_ATTRIBUTES + DEPRECATED + OTHER_ATTRIBUTES) | ||
|
||
attr_accessor(*ALL_ATTRIBUTES) | ||
|
||
validates_presence_of CREATE_REQUIRED | ||
|
||
def self.from_placement(zones) | ||
cuepoints = [] | ||
current_cuepoint = nil | ||
original_duration = 0 | ||
original_count = 0 | ||
zones.each do |zone| | ||
# if this is an ad zone, add it to the cue point | ||
if zone[:type] == "ad" | ||
if current_cuepoint | ||
current_cuepoint.ad_count = current_cuepoint.ad_count + 1 | ||
current_cuepoint.ad_sources << source_for_zone(zone) | ||
else | ||
current_cuepoint = new( | ||
cuepoint_type: "#{zone[:section]}roll", | ||
ad_count: 1, | ||
start_time: original_duration, | ||
ad_sources: [source_for_zone(zone)], | ||
action: :insert, | ||
is_active: true | ||
) | ||
cuepoints << current_cuepoint | ||
end | ||
elsif zone[:type] == "original" | ||
current_cuepoint = nil | ||
original_duration += feeder_episode.media[original_count].duration | ||
original_count += 1 | ||
end | ||
end | ||
end | ||
|
||
def source_for_zone(zone) | ||
if zone[:id].match?(/^house/) | ||
:promo | ||
else | ||
:auto | ||
end | ||
end | ||
|
||
def as_json_for_create | ||
as_json(only: CREATE_ATTRIBUTES.map(&:to_s)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters