class VAST::Creative

Contains the information related to a piece of creative.

Sequence

The Creative element takes an optional “sequence” attribute that indicates the suggested order in which the Creatives should be displayed. If two Creative elements are intended to be shown at the same time they should share the same sequence number.

Public Instance Methods

ad() click to toggle source
# File lib/vast/creative.rb, line 10
def ad
  Ad.create source_node.ancestors('Ad').first
end
ad_id() click to toggle source
# File lib/vast/creative.rb, line 18
def ad_id
  creative_node[:AdID]
end
ad_parameters() click to toggle source

Data to be passed into the video ad.

# File lib/vast/creative.rb, line 28
def ad_parameters
  source_node.at('AdParameters').content
end
id() click to toggle source
# File lib/vast/creative.rb, line 14
def id
  creative_node[:id]
end
sequence() click to toggle source

The preferred order in which multiple Creatives should be displayed

# File lib/vast/creative.rb, line 23
def sequence
  creative_node[:sequence]
end
tracking_urls() click to toggle source

Returns a hash, keyed by event name, containing an array of URIs to be called for each event.

# File lib/vast/creative.rb, line 33
def tracking_urls
  tracking_urls = {}
  source_node.xpath('.//Tracking').to_a.collect do |node|
    underscored_name = underscore(node[:event])
    if tracking_urls[underscored_name.to_sym]
       tracking_urls[underscored_name.to_sym] << URI.parse(node.content.strip)
    else
       tracking_urls[underscored_name.to_sym] = [URI.parse(node.content.strip)]
    end
  end
  tracking_urls
end

Protected Instance Methods

underscore(camel_cased_word) click to toggle source
# File lib/vast/creative.rb, line 48
def underscore(camel_cased_word)
   camel_cased_word.to_s.gsub(/::/, '/').
      gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
      gsub(/([a-z\d])([A-Z])/,'\1_\2').
      tr("-", "_").
      downcase
end

Private Instance Methods

creative_node() click to toggle source
# File lib/vast/creative.rb, line 58
def creative_node
  source_node.ancestors('Creative').first
end