Class: VAST::Document

Inherits:
Nokogiri::XML::Document
  • Object
show all
Defined in:
lib/vast/document.rb

Overview

A complete VAST document

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(*args) ⇒ Object

Parse a VAST XML document



6
7
8
# File 'lib/vast/document.rb', line 6

def self.parse(*args)
  super(*args)
end

.parse!(*args) ⇒ Object

Same as parse, but raises InvalidDocumentError if document is not valid



11
12
13
14
15
# File 'lib/vast/document.rb', line 11

def self.parse!(*args)
  document = parse(*args)
  raise InvalidDocumentError unless document.valid?
  document
end

Instance Method Details

#adsObject

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 the ad.

If no ads of any type are available, it would be indicated by the absence of any ads.



29
30
31
32
33
# File 'lib/vast/document.rb', line 29

def ads
  self.root.xpath('.//Ad').to_a.collect do |node|
    Ad.create(node)
  end
end

#inline_adsObject

All inline ads



36
37
38
# File 'lib/vast/document.rb', line 36

def inline_ads
  ads.select{ |ad| ad.kind_of?(VAST::InlineAd) }
end

#valid?Boolean

Checks whether document conforms to the VAST XML Schema Definitions, accessible at www.iab.net/iab_products_and_industry_services/508676/digitalvideo/vast

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/vast/document.rb', line 19

def valid?
  xsd = Nokogiri::XML::Schema(File.read(VAST_SCHEMA_XSD_FILE))
  xsd.valid?(self)
end

#wrapper_adsObject

All wrapper ads



41
42
43
# File 'lib/vast/document.rb', line 41

def wrapper_ads
  ads.select{ |ad| ad.kind_of?(VAST::WrapperAd) }
end