-
Notifications
You must be signed in to change notification settings - Fork 77
/
Item.js
57 lines (49 loc) · 1.34 KB
/
Item.js
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
var AttributeList = require('./AttributeList');
var Item = module.exports = function Item(attributes) {
this.attributes = new AttributeList(attributes);
this.properties = {
byteRange : null,
daiPlacementOpportunity: null,
date : null,
discontinuity : null,
duration : null,
title : null,
uri : null
};
};
Item.prototype.get = function get(key) {
if (this.propertiesHasKey(key)) {
return this.properties[key];
} else {
return this.attributes.get(key);
}
};
Item.prototype.set = function set(key, value) {
if (this.propertiesHasKey(key)) {
this.properties[key] = value;
} else {
this.attributes.set(key, value);
}
return this;
};
Item.prototype.serialize = function serialize() {
return {
attributes : this.attributes.serialize(),
properties : this.properties
}
};
Item.unserialize = function unserialize(constructor, object) {
var item = new constructor;
item.attributes = AttributeList.unserialize(object.attributes);
item.properties = object.properties;
return item;
};
Item.prototype.setData = function setData(data) {
var self = this;
Object.keys(data).forEach(function(key) {
self.set(key, data[key]);
});
};
Item.prototype.propertiesHasKey = function hasKey(key) {
return Object.keys(this.properties).indexOf(key) > -1;
};