Class: VAST::Document
- Inherits:
-
Nokogiri::XML::Document
- Object
- Nokogiri::XML::Document
- VAST::Document
- Defined in:
- lib/vast/document.rb
Overview
A complete VAST document
Class Method Summary collapse
- .eval_macro(xml_string) ⇒ Object
-
.parse(*args) ⇒ Object
Parse a VAST XML document.
-
.parse!(*args) ⇒ Object
Same as parse, but raises InvalidDocumentError if document is not valid.
Instance Method Summary collapse
- #ad_pod_ads ⇒ Object
-
#ads ⇒ Object
A single VAST response may include multiple Ads from multiple advertisers.
-
#inline_ads ⇒ Object
All inline ads.
- #stand_alone_ads ⇒ Object
-
#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.
-
#wrapper_ads ⇒ Object
All wrapper ads.
Class Method Details
.eval_macro(xml_string) ⇒ Object
6 7 |
# File 'lib/vast/document.rb', line 6 def self.eval_macro(xml_string) end |
.parse(*args) ⇒ Object
Parse a VAST XML document
10 11 12 13 14 15 16 |
# 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) ⇒ Object
Same as parse, but raises InvalidDocumentError if document is not valid
19 20 21 22 23 |
# File 'lib/vast/document.rb', line 19 def self.parse!(*args) document = parse(*args) raise InvalidDocumentError unless document.valid? document end |
Instance Method Details
#ad_pod_ads ⇒ Object
58 59 60 |
# 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 ⇒ Object
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.
47 48 49 50 51 |
# 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 ⇒ Object
All inline ads
54 55 56 |
# File 'lib/vast/document.rb', line 54 def inline_ads ads.select{ |ad| ad.kind_of?(VAST::InlineAd) } end |
#stand_alone_ads ⇒ Object
62 63 64 |
# File 'lib/vast/document.rb', line 62 def stand_alone_ads ads.select{ |ad| !ad.sequence.is_a?(Numeric) } 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
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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 ⇒ Object
All wrapper ads
67 68 69 |
# File 'lib/vast/document.rb', line 67 def wrapper_ads ads.select{ |ad| ad.kind_of?(VAST::WrapperAd) } end |