all files / scripts/ads/vast/ InLine.js

93.94% Statements 31/33
75% Branches 9/12
100% Functions 4/4
93.94% Lines 31/33
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66        51×         51× 51× 51× 51×     51× 51× 51× 51× 51× 51×     51×                 50×                              
'use strict';
 
var vastUtil = require('./vastUtil');
var Creative = require('./Creative');
 
var utilities = require('../../utils/utilityFunctions');
var xml = require('../../utils/xml');
 
function InLine(inlineJTree) {
  Iif (!(this instanceof InLine)) {
    return new InLine(inlineJTree);
  }
 
  //Required Fields
  this.adTitle = xml.keyValue(inlineJTree.adTitle);
  this.adSystem = xml.keyValue(inlineJTree.adSystem);
  this.impressions = vastUtil.parseImpressions(inlineJTree.impression);
  this.creatives = Creative.parseCreatives(inlineJTree.creatives);
 
  //Optional Fields
  this.description = xml.keyValue(inlineJTree.description);
  this.advertiser = xml.keyValue(inlineJTree.advertiser);
  this.surveys = parseSurveys(inlineJTree.survey);
  this.error = xml.keyValue(inlineJTree.error);
  this.pricing = xml.keyValue(inlineJTree.pricing);
  this.extensions = inlineJTree.extensions;
 
  /*** Local Functions ***/
  function parseSurveys(inlineSurveys) {
    if (inlineSurveys) {
      return utilities.transformArray(utilities.isArray(inlineSurveys) ? inlineSurveys : [inlineSurveys], function (survey) {
        Eif(utilities.isNotEmptyString(survey.keyValue)){
          return {
            uri: survey.keyValue,
            type: survey.attr('type')
          };
        }
 
        return undefined;
      });
    }
    return [];
  }
}
 
 
/**
 * Returns true if the browser supports all the creatives.
 */
InLine.prototype.isSupported = function(){
  var i,len;
 
  if(this.creatives.length === 0) {
    return false;
  }
 
  for(i = 0, len = this.creatives.length; i< len; i+=1){
    if(!this.creatives[i].isSupported()){
      return false;
    }
  }
  return true;
};
 
module.exports = InLine;