@rr0/data
Version:
RR0 data model
33 lines (32 loc) • 1.08 kB
JavaScript
import { RR0Event } from "./RR0Event.js";
import { NamedPlace } from "@rr0/place";
import { Level2Date as EdtfDate } from "@rr0/time";
import { TypedDataFactory } from "../TypedDataFactory.js";
export class RR0EventFactory extends TypedDataFactory {
constructor() {
super(null, "event");
this.eventFactory = this;
}
parse(eventJson) {
const data = super.parse(eventJson);
const time = eventJson.time ? EdtfDate.fromString(eventJson.time) : undefined;
const eventType = eventJson.eventType || eventJson["type"];
let placeJson = eventJson.place;
let place;
if (typeof placeJson === "string") {
place = new NamedPlace(placeJson);
}
const event = new RR0Event(eventType, time);
Object.assign(event, {
id: data.id,
dirName: data.dirName,
name: data.name,
title: data.title,
url: data.url,
place,
sources: data.sources,
notes: data.notes
});
return event;
}
}