UNPKG

silegismg-interpretador-articulacao

Version:
75 lines (74 loc) 2.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TipoAgrupador = exports.TipoDispositivo = void 0; /* Copyright 2017 Assembleia Legislativa de Minas Gerais * * This file is part of Interpretador-Articulacao. * * Interpretador-Articulacao is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, version 3. * * Interpretador-Articulacao is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with Interpretador-Articulacao. If not, see <http://www.gnu.org/licenses/>. */ var TipoDispositivo; (function (TipoDispositivo) { TipoDispositivo["ARTIGO"] = "artigo"; TipoDispositivo["PARAGRAFO"] = "paragrafo"; TipoDispositivo["INCISO"] = "inciso"; TipoDispositivo["ALINEA"] = "alinea"; TipoDispositivo["ITEM"] = "item"; })(TipoDispositivo || (exports.TipoDispositivo = TipoDispositivo = {})); var TipoAgrupador; (function (TipoAgrupador) { TipoAgrupador["TITULO"] = "titulo"; TipoAgrupador["CAPITULO"] = "capitulo"; TipoAgrupador["SECAO"] = "secao"; TipoAgrupador["SUBSECAO"] = "subsecao"; })(TipoAgrupador || (exports.TipoAgrupador = TipoAgrupador = {})); class Dispositivo { get subitens() { return this.derivacoes ? this.derivacoes.reduce((prev, item) => item in this ? prev.concat(this[item]) : prev, []) : []; } constructor(tipo, numero, descricao, derivacoes) { this.tipo = tipo; this.numero = numero; this.descricao = descricao; this.derivacoes = derivacoes; } /** * Adiciona um dispositivo a este. * * @param {TiposDerivaveis} dispositivo */ adicionar(dispositivo) { const tipo = dispositivo.tipo; const atributo = tipo + 's'; if (!(atributo in this)) { throw new Error(`Derivação "${tipo}" não suportada em "${this.tipo}".`); } this[atributo].push(dispositivo); Object.defineProperty(dispositivo, '$parent', { value: this }); } remover(dispositivo) { const tipo = dispositivo.tipo; const atributo = tipo + 's'; if (!(atributo in this)) { throw new Error(`Derivação "${tipo}" não suportada em "${this.tipo}".`); } const idx = this[atributo].indexOf(dispositivo); if (idx === -1) { throw new Error('Dispositivo não encontrado.'); } this[atributo].splice(idx, 1); } } exports.default = Dispositivo;