UNPKG

s2-tools

Version:

A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.

123 lines 3.71 kB
import { parseCSVAsRecord } from '../../'; /** * Indicates an organization’s role in producing the dataset: * 0 or empty = No role * 1 = Has the role * * At least one of is_producer, is_operator, or is_authority should be 1 in each record. */ export var GTFSAttributionRole; (function (GTFSAttributionRole) { GTFSAttributionRole[GTFSAttributionRole["None"] = 0] = "None"; GTFSAttributionRole[GTFSAttributionRole["Yes"] = 1] = "Yes"; })(GTFSAttributionRole || (GTFSAttributionRole = {})); /** * # Attributions * * **Optional** * Defines the attributions applied to the dataset or parts of it. * If `agency_id`, `route_id`, or `trip_id` is specified, the attribution * applies only to that entity. If none are specified, the attribution * applies to the entire dataset. * * **Primary Key**: (attribution_id) - optional */ export class GTFSAttribution { /** * **Optional** * Unique ID that identifies this attribution record. * Useful if multiple attributions exist or for referencing translations. */ id; /** * **Optional** * Agency to which this attribution applies (`agency.agency_id`). * Must be empty if route_id or trip_id are specified. */ agencyId; /** * **Optional** * Route to which this attribution applies (`routes.route_id`). * Must be empty if agency_id or trip_id are specified. */ routeId; /** * **Optional** * Trip to which this attribution applies (`trips.trip_id`). * Must be empty if agency_id or route_id are specified. */ tripId; /** * **Required** * Organization name to which the dataset is attributed. */ organizationName; /** * **Optional** * 0 or empty = Not a producer, 1 = Is a producer */ isProducer; /** * **Optional** * 0 or empty = Not an operator, 1 = Is an operator */ isOperator; /** * **Optional** * 0 or empty = Not an authority, 1 = Is an authority */ isAuthority; /** * **Optional** * URL of the organization. */ attributionUrl; /** * **Optional** * Email of the organization. */ attributionEmail; /** * **Optional** * Phone number of the organization. */ attributionPhone; /** @param data - the parsed GTFS CSV data */ constructor(data) { this.id = data.attribution_id; this.agencyId = data.agency_id; this.routeId = data.route_id; this.tripId = data.trip_id; this.organizationName = data.organization_name; this.attributionUrl = data.attribution_url; this.attributionEmail = data.attribution_email; this.attributionPhone = data.attribution_phone; // Roles: if empty, default to 'None' this.isProducer = data.is_producer !== undefined ? parseInt(data.is_producer, 10) : GTFSAttributionRole.None; this.isOperator = data.is_operator !== undefined ? parseInt(data.is_operator, 10) : GTFSAttributionRole.None; this.isAuthority = data.is_authority !== undefined ? parseInt(data.is_authority, 10) : GTFSAttributionRole.None; } } /** * @param input - the input string to parse from * @returns - an array of Attributions */ export function parseGTFSAttributions(input) { const data = parseCSVAsRecord(input); const res = {}; for (const d of data) { const attribution = new GTFSAttribution(d); res[attribution.organizationName] = attribution; } return res; } //# sourceMappingURL=attributions.js.map