UNPKG

s2-tools

Version:

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

108 lines 3.17 kB
import { parseCSVAsRecord } from '../../'; /** * NOTE: * The files associated with GTFS-Fares V1 are: * - fare_attributes.txt * - fare_rules.txt * * The files associated with GTFS-Fares V2 are: * - fare_media.txt * - fare_products.txt * - fare_leg_rules.txt * - fare_transfer_rules.txt */ /** * * Indicates when the fare must be paid: * - 0 = On board * - 1 = Before boarding */ export var GTFSPaymentMethod; (function (GTFSPaymentMethod) { GTFSPaymentMethod[GTFSPaymentMethod["OnBoard"] = 0] = "OnBoard"; GTFSPaymentMethod[GTFSPaymentMethod["PreBoard"] = 1] = "PreBoard"; })(GTFSPaymentMethod || (GTFSPaymentMethod = {})); /** * # Fare Attributes (GTFS-Fares V1) * * **Optional** - But required if using GTFS-Fares V1 approach. * Defines basic fare information such as price, currency, and transfer limits. */ export class GTFSFareAttribute { /** * **Required** * Identifies a fare class. */ id; /** * **Required** * Fare price in the currency specified by `currencyType`. */ price; /** * **Required** * Currency code (e.g., "USD", "EUR"). */ currencyType; /** * **Required** * When the fare must be paid. * - 0 = Paid on board * - 1 = Must be paid before boarding */ paymentMethod; /** * **Required** * Number of transfers permitted on this fare. * - 0 = No transfers * - 1 = One transfer * - 2 = Two transfers * - '' (empty) = Unlimited transfers */ transfers; /** * **Conditionally Required** * Agency for the specified fare. * Required if multiple agencies exist in `agency.txt`. */ agencyId; /** * **Optional** * Length of time in seconds before a transfer (or this fare) expires. * When transfers=0, may indicate ticket validity duration or be empty. */ transferDuration; /** @param data - the parsed GTFS CSV data */ constructor(data) { this.id = data.fare_id; this.price = data.price !== undefined ? parseFloat(data.price) : 0; this.currencyType = data.currency_type; this.paymentMethod = data.payment_method !== undefined ? parseInt(data.payment_method, 10) : GTFSPaymentMethod.OnBoard; // If transfers is an empty string, interpret as unlimited. // Otherwise, parse the number or set it to empty string. this.transfers = data.transfers !== undefined ? parseInt(data.transfers, 10) : ''; this.agencyId = data.agency_id; this.transferDuration = data.transfer_duration !== undefined && data.transfer_duration !== '' ? parseInt(data.transfer_duration, 10) : undefined; } } /** * @param input - the input string to parse from * @returns - an array of GTFSFareAttributes */ export function parseGTFSFareAttributes(input) { const data = parseCSVAsRecord(input); const res = {}; for (const d of data) { const fa = new GTFSFareAttribute(d); res[fa.id] = fa; } return res; } //# sourceMappingURL=fareAttributes.js.map