class VAST::Document

A complete VAST document

Public Class Methods

eval_macro(xml_string) click to toggle source
# File lib/vast/document.rb, line 6
def self.eval_macro(xml_string)
end
parse(*args) click to toggle source

Parse a VAST XML document

Calls superclass method
# File lib/vast/document.rb, line 10
def self.parse(*args)
  # VAST 3 support macro, need to uri escape all macros
  if (args[0].is_a? String)
    @macros.each{|x|  args[0].gsub!("[#{x}]", "%5B#{x}%5D")}
  end
  super(*args)
end
parse!(*args) click to toggle source

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

# File lib/vast/document.rb, line 19
def self.parse!(*args)
  document = parse(*args)
  raise InvalidDocumentError unless document.valid?
  document
end

Public Instance Methods

ad_pod_ads() click to toggle source
# File lib/vast/document.rb, line 58
def ad_pod_ads
  ads.select{ |ad| ad.sequence.is_a? Numeric }.sort{|x, y| x.sequence <=> y.sequence }
end
ads() click to toggle source

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.

# File lib/vast/document.rb, line 47
def ads
  self.root.xpath('.//Ad').to_a.collect do |node|
    Ad.create(node)
  end
end
inline_ads() click to toggle source

All inline ads

# File lib/vast/document.rb, line 54
def inline_ads
  ads.select{ |ad| ad.kind_of?(VAST::InlineAd) }
end
stand_alone_ads() click to toggle source
# File lib/vast/document.rb, line 62
def stand_alone_ads
  ads.select{ |ad| !ad.sequence.is_a?(Numeric) }
end
valid?() click to toggle source

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

# File lib/vast/document.rb, line 27
def valid?
  version_node = self.xpath('/VAST/@version').first
  major_version = version_node ? version_node.value.to_i : 0
  case major_version
  when 2
    xsd_file = VAST_SCHEMA_XSD_FILE
  when 3
    xsd_file = VAST3_SCHEMA_XSD_FILE
  else
    return false
  end
  xsd = Nokogiri::XML::Schema(File.read(xsd_file))
  xsd.valid?(self)
end
wrapper_ads() click to toggle source

All wrapper ads

# File lib/vast/document.rb, line 67
def wrapper_ads
  ads.select{ |ad| ad.kind_of?(VAST::WrapperAd) }
end