2016-04-25 03:28:02 +01:00
|
|
|
import * as _ from "lodash";
|
2017-03-08 21:49:41 +00:00
|
|
|
import { BaseXmlComponent } from "./base";
|
2017-03-09 20:49:14 +01:00
|
|
|
export { BaseXmlComponent };
|
2016-04-25 03:28:02 +01:00
|
|
|
|
2016-04-21 23:27:46 +01:00
|
|
|
export abstract class XmlComponent extends BaseXmlComponent {
|
2017-03-09 19:50:33 +01:00
|
|
|
protected root: Array<BaseXmlComponent | string>;
|
2016-04-21 23:27:46 +01:00
|
|
|
|
|
|
|
constructor(rootKey: string) {
|
|
|
|
super(rootKey);
|
|
|
|
this.root = new Array<BaseXmlComponent>();
|
|
|
|
}
|
|
|
|
|
2017-03-09 20:49:14 +01:00
|
|
|
public toXml(): object {
|
2017-03-09 22:57:30 +00:00
|
|
|
// What does 'ret' stand for? Retain? Return?
|
2017-03-09 20:49:14 +01:00
|
|
|
const ret = this.root.map((comp) => {
|
|
|
|
if (comp instanceof BaseXmlComponent) {
|
|
|
|
return comp.toXml();
|
|
|
|
}
|
2017-03-09 22:57:37 +00:00
|
|
|
return comp;
|
2017-03-09 20:49:14 +01:00
|
|
|
}).filter((comp) => comp); // Exclude null, undefined, and empty strings
|
|
|
|
return {
|
|
|
|
[this.rootKey]: ret,
|
2017-03-09 22:57:37 +00:00
|
|
|
};
|
2016-04-21 23:27:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-20 00:40:31 +01:00
|
|
|
export * from "./attributes"
|
|
|
|
export * from "./default-attributes";
|