Class: VAST::Ad

Inherits:
Element show all
Defined in:
lib/vast/ad.rb

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.

Direct Known Subclasses

InlineAd, WrapperAd

Instance Attribute Summary

Attributes inherited from Element

#source_node

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Element

#initialize

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_systemObject

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_creativesObject

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_urlObject

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

#extensionsObject

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

#idObject

Ad id, if indicated



32
33
34
# File 'lib/vast/ad.rb', line 32

def id
  source_node[:id]
end

#impressionObject

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

#impressionsObject

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_creativeObject

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_creativesObject

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_creativesObject

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