Skip to content

Commit

Permalink
Parse all nonlinear attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
briganti authored and johansatge committed Apr 14, 2017
1 parent 74acae8 commit a26c33b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/nonlinear.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ class VASTNonLinear
@id = null
@width = 0
@height = 0
@minSuggestedDuration = "00:00:00"
@expandedWidth = 0
@expandedHeight = 0
@scalable = true
@maintainAspectRatio = true
@minSuggestedDuration = 0
@apiFramework = "static"
@type = null
@staticResource = null
Expand Down
9 changes: 8 additions & 1 deletion src/parser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,11 @@ class VASTParser
nonlinearAd.id = nonlinearResource.getAttribute("id") or null
nonlinearAd.width = nonlinearResource.getAttribute("width")
nonlinearAd.height = nonlinearResource.getAttribute("height")
nonlinearAd.minSuggestedDuration = nonlinearResource.getAttribute("minSuggestedDuration")
nonlinearAd.expandedWidth = nonlinearResource.getAttribute("expandedWidth")
nonlinearAd.expandedHeight = nonlinearResource.getAttribute("expandedHeight")
nonlinearAd.scalable = @parseBoolean nonlinearResource.getAttribute("scalable")
nonlinearAd.maintainAspectRatio = @parseBoolean nonlinearResource.getAttribute("maintainAspectRatio")
nonlinearAd.minSuggestedDuration = @parseDuration nonlinearResource.getAttribute("minSuggestedDuration")
nonlinearAd.apiFramework = nonlinearResource.getAttribute("apiFramework")

for htmlElement in @childsByName(nonlinearResource, "HTMLResource")
Expand Down Expand Up @@ -528,6 +532,9 @@ class VASTParser

return parseInt yPosition or 0

@parseBoolean: (booleanString) ->
return booleanString in ['true', 'TRUE', '1']

# Parsing node text for legacy support
@parseNodeText: (node) ->
return node and (node.textContent or node.text or '').trim()
Expand Down
8 changes: 7 additions & 1 deletion test/parser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,15 @@ describe 'VASTParser', ->
after () =>
nonlinear = null

it 'should have parsed size and type attributes', =>
it 'should have parsed attributes', =>
nonlinear.width.should.equal '300'
nonlinear.height.should.equal '200'
nonlinear.expandedWidth.should.equal '600'
nonlinear.expandedHeight.should.equal '400'
nonlinear.scalable.should.equal false
nonlinear.maintainAspectRatio.should.equal true
nonlinear.minSuggestedDuration.should.equal 100
nonlinear.apiFramework.should.equal "someAPI"
nonlinear.type.should.equal 'image/jpeg'

it 'should have 1 nonlinear clickthrough url', =>
Expand Down
2 changes: 1 addition & 1 deletion test/sample.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
</Creative>
<Creative>
<NonLinearAds>
<NonLinear width="300" height="200">
<NonLinear width="300" height="200" expandedWidth="600" expandedHeight="400" scalable="false" maintainAspectRatio="true" minSuggestedDuration="00:01:40" apiFramework="someAPI" >
<StaticResource creativeType="image/jpeg"><![CDATA[http://example.com/nonlinear-static-resource]]></StaticResource>
<AdParameters>
<![CDATA[{"key":"value"}]]>
Expand Down

0 comments on commit a26c33b

Please sign in to comment.