blob: d1df91fe240430948c97bf9e56ac68ae340cbfdc (
plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
var Immutable = require('immutable');
var File = require('./file');
var SummaryPart = require('./summaryPart');
var SummaryArticle = require('./summaryArticle');
var Summary = Immutable.Record({
file: File(),
parts: Immutable.List()
}, 'Summary');
Summary.prototype.getFile = function() {
return this.get('file');
};
Summary.prototype.getParts = function() {
return this.get('parts');
};
/**
Return an article using an iterator to find it
@param {Function} iter
@return {Article}
*/
Summary.prototype.getArticle = function(iter) {
var parts = this.getParts();
return parts.reduce(function(result, part) {
if (result) return result;
return SummaryArticle.findArticle(part, iter);
}, null);
};
/**
Return a part/article by its level
@param {String} level
@return {Article}
*/
Summary.prototype.getByLevel = function(level) {
return this.getArticle(function(article) {
return (article.getLevel() === level);
});
};
/**
Return an article by its path
@param {String} filePath
@return {Article}
*/
Summary.prototype.getByPath = function(filePath) {
return this.getArticle(function(article) {
return (article.getPath() === filePath);
});
};
/**
Create a new summary for a list of parts
@param {Lust|Array} parts
@return {Summary}
*/
Summary.createFromParts = function createFromParts(file, parts) {
parts = parts.map(function(part, i) {
if (part instanceof SummaryPart) {
return part;
}
return SummaryPart.create(part, i);
});
return new Summary({
file: file,
parts: new Immutable.List(parts)
});
};
module.exports = Summary;
|