-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeature.js
More file actions
54 lines (46 loc) · 1.65 KB
/
feature.js
File metadata and controls
54 lines (46 loc) · 1.65 KB
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
function Feature(node, parent, children) {
if (!(this instanceof Feature))
return new Feature(node, parent, children);
var self = this;
function getDescription(node) {
var description = node.find("> description").get();
return description.length === 1 ?
$(description[0]).text().split("\n").map(function(line) { return line.trim(); }).join("\n").trim() :
null;
}
this.name = node.attr("name");
this.description = getDescription(node);
this.mandatory = node.attr("mandatory") === "true";
this.alternative = node.prop("tagName") === "alt";
this.or = node.prop("tagName") === "or";
this.parent = parent ? new Feature(parent) : null;
if (children && (this.alternative || this.or))
this.children = children.get().filter(function(child) {
return ["feature", "and", "or", "alt"].includes($(child).prop("tagName"));
}).map(function(child) {
return Feature($(child));
});
// extension to FeatureIDE models to support value features (features with string values)
this.value = node.attr("value");
this.hasValue = typeof this.value !== typeof undefined && this.value !== false;
this.setValue = function(value) {
if (!self.hasValue)
throw "not a value feature";
self.value = value;
};
}
function featureFinder(name) {
return function(feature) {
return feature.name === name;
};
}
function featureGetter(key) {
return function(name) {
return this[key].find(featureFinder(name));
};
}
function featureName() {
return function(feature) {
return feature.name;
};
}