gistools/readers/gtfs/schedule/
feed_info.rs

1use crate::readers::csv::parse_csv_as_record;
2use alloc::{collections::BTreeMap, string::String};
3use s2json::MValueCompatible;
4
5/// # Feed Information
6///
7/// **Conditionally Required**
8/// Contains information about the dataset itself (publisher, version, etc.).
9/// - Required if `translations.txt` is used.
10/// - Recommended otherwise.
11#[derive(Debug, Default, Clone, PartialEq, MValueCompatible)]
12pub struct GTFSFeedInfo {
13    /// **Required**
14    /// Full name of the organization that publishes the dataset.
15    pub feed_publisher_name: String,
16    /// **Required**
17    /// URL of the dataset publisher's website.
18    pub feed_publisher_url: String,
19    /// **Required**
20    /// Default language code for the text in this dataset.
21    /// For multilingual datasets, use "mul" and translations.txt for further detail.
22    pub feed_lang: String,
23    /// **Optional**
24    /// Language used if the consumer does not know the rider’s language, often "en".
25    pub default_lang: Option<String>,
26    /// **Recommended**
27    /// First date of service the dataset covers, in `YYYYMMDD` format.
28    pub feed_start_date: Option<String>,
29    /// **Recommended**
30    /// Last date of service the dataset covers, in `YYYYMMDD` format.
31    /// Must not precede `feed_start_date` if both are given.
32    pub feed_end_date: Option<String>,
33    /// **Recommended**
34    /// Current version identifier for this GTFS dataset.
35    pub feed_version: Option<String>,
36    /// **Optional**
37    /// Email address for technical contact about the dataset.
38    pub feed_contact_email: Option<String>,
39    /// **Optional**
40    /// URL for technical contact or support form regarding the dataset.
41    pub feed_contact_url: Option<String>,
42}
43impl GTFSFeedInfo {
44    /// Create a new GTFSFeedInfo
45    pub fn new(source: &str) -> BTreeMap<String, GTFSFeedInfo> {
46        let mut res = BTreeMap::new();
47        for record in parse_csv_as_record::<GTFSFeedInfo>(source, None, None) {
48            res.insert(record.feed_publisher_name.clone(), record);
49        }
50        res
51    }
52}