UNPKG

@rr0/cms

Version:

RR0 Content Management System (CMS)

49 lines (48 loc) 2.13 kB
import assert from "assert"; import { Level2Date as EdtfDate } from "@rr0/time"; import { OrganizationPlace } from "../../../place/OrganizationPlace.js"; export class UrecatRR0Mapper { constructor(cityService, countryService, baseUrl, copyright, authors) { this.cityService = cityService; this.countryService = countryService; this.baseUrl = baseUrl; this.copyright = copyright; this.authors = authors; } getDescription(c) { const description = ["observation"]; return description.join(", "); } map(context, sourceCase, sourceTime) { const caseSource = { events: [], previousSourceRefs: [], url: sourceCase.url, title: "cas n° " + sourceCase.id, authors: this.authors, publication: { publisher: this.copyright, time: EdtfDate.fromDate(sourceTime) } }; const location = sourceCase.basicInfo.base.location; let sourceCountry = location.country; assert.ok(sourceCountry, `URECAT country is ${sourceCountry}`); const fromPrefix = "depuis "; if (sourceCountry.startsWith(fromPrefix)) { sourceCountry = sourceCountry.substring(fromPrefix.length); } const country = this.countryService.find(context, sourceCountry, undefined); assert.ok(country, `Could not find country "${sourceCountry}"`); const placeItems = /(.+?)(:?\s+\((.+)\))?$/.exec(location.placeName); const placeName = placeItems[1]; const city = this.cityService.find(context, placeName, undefined); assert.ok(city, `Could not find city of name "${placeName}" in state "${location.departmentOrState}" of country "${sourceCountry}"`); const place = new OrganizationPlace(city); return { type: "event", eventType: "sighting", id: sourceCase.id, url: sourceCase.url, events: [], time: sourceCase.basicInfo.base.sightingDate, place, description: this.getDescription(sourceCase), sources: [caseSource] }; } }