Source: data/PangaeaDatasetDescription.js

import { DatasetDescription } from './DatasetDescription.js';

/**
 * A reader for PANGAEA dataset descriptions.
 * 
 * @author rkoppe <roland.koppe@awi.de>
 */
export class PangaeaDatasetDescription extends DatasetDescription {

    /**
     * Parses a PangaeaDataDescription from given content.
     * 
     * @param {string} content 
     */
    constructor(content) {
        super();

        let lines = content.split('\n');
        let key = null;
        for (let i = 0; i < lines.length; i++) {
            let line = lines[i].trim();
            let parts = line.split('\t', 2);

            if (parts[0] != '') key = parts[0].slice(0, -1).trim().toLocaleLowerCase();
            let value = parts[1];

            if (key == 'citation') {
                this.citation = value;

            } else if (key == 'related to') {
                this.relations.relatedTo.push(value);

            } else if (key == 'further details') {
                this.relations.furtherDetails.push(value);

            } else if (key == 'project(s)') {
                this.projects.push(value);

            } else if (key == 'event(s)') {
                parts = value.split('*');
                let map = {};
                parts.slice(1).map(x => {
                    let parts = x.split(':', 2);
                    map[parts[0].trim().toLocaleLowerCase()] = parts[1].trim();
                });

                this.events[parts[0].trim()] = map;

            } else if (key == 'parameter(s)') {
                this.parameters.push(value);

            } else if (key == 'license') {
                this.license = value;
            }
        }
    }
}