UNPKG

@giancosta86/omnicourse-core

Version:
32 lines 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Taxonomy = void 0; const Subject_1 = require("./Subject"); const SubjectSet_1 = require("./SubjectSet"); class Taxonomy { static create(locale, name, subjects) { const subjectSet = SubjectSet_1.SubjectSet.createSorted(locale, subjects); if (!subjectSet.nonEmpty()) { throw new Error(`No subjects for taxonomy '${name}'`); } return new Taxonomy(name, subjectSet); } static equals(left, right) { return (left.name === right.name && left.totalMinutes === right.totalMinutes && left.items.stream().equals(right.items, Subject_1.Subject.equals)); } constructor(name, items) { this.name = name; this.items = items; this.containsSubjects = true; if (!name) { throw new Error("Empty taxonomy name"); } this.totalMinutes = this.items .stream() .fold(0, (cumulatedMinutes, subject) => cumulatedMinutes + subject.totalMinutes); } } exports.Taxonomy = Taxonomy; //# sourceMappingURL=Taxonomy.js.map