-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDocBase.ts
More file actions
44 lines (38 loc) · 988 Bytes
/
DocBase.ts
File metadata and controls
44 lines (38 loc) · 988 Bytes
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
import NuggetDocument from './NuggetDocument';
/**
* Base class for a document base.
*/
class DocBase {
readonly name: string;
readonly organizationId: number;
attributes: string[];
docs: NuggetDocument[];
constructor(name: string, organizationId: number, attributes: string[]) {
this.name = name;
this.organizationId = organizationId;
this.attributes = attributes;
this.docs = [];
}
addNuggetDocument(doc: NuggetDocument): void {
this.docs.push(doc);
}
addNugget(
docName: string,
docContent: string,
startChar: number,
endChar: number
) {
const doc = this.docs.find((doc) => doc.isSame(docName, docContent));
if (doc !== undefined) {
doc.addNugget(startChar, endChar);
return;
}
const newDoc = new NuggetDocument(docName, docContent);
newDoc.addNugget(startChar, endChar);
this.docs.push(newDoc);
}
async fetchOrderedNuggets() {
await this.docs[0].fetchOrderNuggets(this.organizationId, this.name);
}
}
export default DocBase;