Class: VAST::Ad
Overview
Contains some combination of video, companions, and non-linear units for a single advertiser.
A single VAST response may include multiple Ads from multiple advertisers. It will be up to the Video Player to determine the order, timing, placement, etc for the multiple ads. However, the player should generally respect the sequential order of the Ad elements within a VAST response.
The VAST response does not contain information on the placement or timing of each ad. It is up to the Video Player to determine the optimal inclusion points of the ads.
Can either be a InlineAd, meaning it contains all the elements necessary to display the visual experience, or a WrapperAd, which points to a downstream VAST document that must be requested from another server.
An Ad may include one or more pieces of creative that are part of a single execution. For example, an Ad may include a linear video element with a set of companion banners; this would be reflected by two Creative elements, one LinearCreative and one CompanionCreative.
Instance Attribute Summary
Attributes inherited from Element
Class Method Summary collapse
-
.create(node) ⇒ Object
Creates proper ad type.
Instance Method Summary collapse
-
#ad_system ⇒ Object
Returns name of source ad server.
-
#companion_creatives ⇒ Object
Returns an array containing all companion creatives.
-
#error_url ⇒ Object
Returns URI to request if ad does not play due to error.
-
#extensions ⇒ Object
All extensions included with this ad.
-
#id ⇒ Object
Ad id, if indicated.
-
#impression ⇒ Object
Each Ad must contain at least one impression.
-
#impressions ⇒ Object
Array of all impressions available for this ad, excluding those specific to a particular creative.
-
#linear_creative ⇒ Object
This is a convenience method for when only the first piece of linear creative is needed.
-
#linear_creatives ⇒ Object
Returns an array containing all linear creatives.
-
#non_linear_creatives ⇒ Object
Returns an array containing all non linear creatives.
Methods inherited from Element
Constructor Details
This class inherits a constructor from VAST::Element
Class Method Details
.create(node) ⇒ Object
Creates proper ad type
21 22 23 24 25 26 27 28 29 |
# File 'lib/vast/ad.rb', line 21 def self.create(node) if node.at('InLine') InlineAd.new(node) elsif node.at('Wrapper') WrapperAd.new(node) else raise InvalidAdError end end |
Instance Method Details
#ad_system ⇒ Object
Returns name of source ad server
37 38 39 40 41 42 43 44 |
# File 'lib/vast/ad.rb', line 37 def ad_system ad_system_node = source_node.at("AdSystem") if ad_system_node ad_system_node.content else raise InvalidAdError, "missing AdSystem node in Ad" end end |
#companion_creatives ⇒ Object
Returns an array containing all companion creatives.
73 74 75 76 77 |
# File 'lib/vast/ad.rb', line 73 def companion_creatives source_node.xpath('.//Creative/CompanionAds/Companion').to_a.collect do |node| CompanionCreative.new(node) end end |
#error_url ⇒ Object
Returns URI to request if ad does not play due to error.
47 48 49 50 |
# File 'lib/vast/ad.rb', line 47 def error_url error_url_node = source_node.at("Error") URI.parse(error_url_node.content.strip) if error_url_node end |
#extensions ⇒ Object
All extensions included with this ad.
93 94 95 96 97 |
# File 'lib/vast/ad.rb', line 93 def extensions source_node.xpath('.//Extension').to_a.collect do |node| Extension.new(node) end end |
#id ⇒ Object
Ad id, if indicated
32 33 34 |
# File 'lib/vast/ad.rb', line 32 def id source_node[:id] end |
#impression ⇒ Object
Each Ad must contain at least one impression.
80 81 82 |
# File 'lib/vast/ad.rb', line 80 def impression URI.parse(source_node.at('Impression').content.strip) end |
#impressions ⇒ Object
Array of all impressions available for this ad, excluding those specific to a particular creative.
86 87 88 89 90 |
# File 'lib/vast/ad.rb', line 86 def impressions source_node.xpath('.//Impression').to_a.collect do |node| URI.parse(node.content.strip) end end |
#linear_creative ⇒ Object
This is a convenience method for when only the first piece of linear creative is needed. It’s common for an ad to contain only one piece of linear creative.
61 62 63 |
# File 'lib/vast/ad.rb', line 61 def linear_creative linear_creatives.first end |
#linear_creatives ⇒ Object
Returns an array containing all linear creatives.
53 54 55 56 57 |
# File 'lib/vast/ad.rb', line 53 def linear_creatives source_node.xpath('.//Creative/Linear').to_a.collect do |node| LinearCreative.new(node) end end |
#non_linear_creatives ⇒ Object
Returns an array containing all non linear creatives.
66 67 68 69 70 |
# File 'lib/vast/ad.rb', line 66 def non_linear_creatives source_node.xpath('.//Creative/NonLinearAds/NonLinear').to_a.collect do |node| NonLinearCreative.new(node) end end |