gistools/readers/gtfs/schedule/attributions.rs
1use crate::readers::csv::parse_csv_as_record;
2use alloc::{collections::BTreeMap, string::String};
3use s2json::MValueCompatible;
4
5/// # Attributions
6///
7/// **Optional**
8/// Defines the attributions applied to the dataset or parts of it.
9/// If `agency_id`, `route_id`, or `trip_id` is specified, the attribution
10/// applies only to that entity. If none are specified, the attribution
11/// applies to the entire dataset.
12///
13/// **Primary Key**: (attribution_id) - optional
14#[derive(Debug, Default, Clone, PartialEq, MValueCompatible)]
15pub struct GTFSAttribution {
16 /// **Optional**
17 /// Unique ID that identifies this attribution record.
18 /// Useful if multiple attributions exist or for referencing translations.
19 pub attribution_id: Option<String>,
20 /// **Optional**
21 /// Agency to which this attribution applies (`agency.agency_id`).
22 /// Must be empty if route_id or trip_id are specified.
23 pub agency_id: Option<String>,
24 /// **Optional**
25 /// Route to which this attribution applies (`routes.route_id`).
26 /// Must be empty if agency_id or trip_id are specified.
27 pub route_id: Option<String>,
28 /// **Optional**
29 /// Trip to which this attribution applies (`trips.trip_id`).
30 /// Must be empty if agency_id or route_id are specified.
31 pub trip_id: Option<String>,
32 /// **Required**
33 /// Organization name to which the dataset is attributed.
34 pub organization_name: String,
35 /// **Optional**
36 /// 0 or empty = Not a producer, 1 = Is a producer
37 pub is_producer: Option<String>,
38 /// **Optional**
39 /// 0 or empty = Not an operator, 1 = Is an operator
40 pub is_operator: Option<String>,
41 /// **Optional**
42 /// 0 or empty = Not an authority, 1 = Is an authority
43 pub is_authority: Option<String>,
44 /// **Optional**
45 /// URL of the organization.
46 pub attribution_url: Option<String>,
47 /// **Optional**
48 /// Email of the organization.
49 pub attribution_email: Option<String>,
50 /// **Optional**
51 /// Phone number of the organization.
52 pub attribution_phone: Option<String>,
53}
54impl GTFSAttribution {
55 /// Create a new GTFSAttribution
56 pub fn new(source: &str) -> BTreeMap<String, GTFSAttribution> {
57 let mut res = BTreeMap::new();
58 for record in parse_csv_as_record::<GTFSAttribution>(source, None, None) {
59 res.insert(record.organization_name.clone(), record);
60 }
61 res
62 }
63 /// Check if is_producer is true
64 pub fn is_producer(&self) -> bool {
65 self.is_producer == Some("1".into())
66 }
67 /// Check if is_operator is true
68 pub fn is_operator(&self) -> bool {
69 self.is_operator == Some("1".into())
70 }
71 /// Check if is_authority is true
72 pub fn is_authority(&self) -> bool {
73 self.is_authority == Some("1".into())
74 }
75}