-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] Add Operator for NeTEx France
- Loading branch information
1 parent
cdc762e
commit 2c03646
Showing
8 changed files
with
160 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// Copyright (C) 2017 Kisio Digital and/or its affiliates. | ||
// | ||
// This program is free software: you can redistribute it and/or modify it | ||
// under the terms of the GNU Affero General Public License as published by the | ||
// Free Software Foundation, version 3. | ||
|
||
// This program is distributed in the hope that it will be useful, but WITHOUT | ||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more | ||
// details. | ||
|
||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/> | ||
|
||
use crate::{ | ||
netex_france::exporter::{Exporter, ObjectType}, | ||
objects::Company, | ||
Model, | ||
}; | ||
use minidom::{Element, Node}; | ||
|
||
pub struct CompanyExporter<'a> { | ||
model: &'a Model, | ||
} | ||
|
||
// Publicly exposed methods | ||
impl<'a> CompanyExporter<'a> { | ||
pub fn new(model: &'a Model) -> Self { | ||
CompanyExporter { model } | ||
} | ||
pub fn export(&self) -> Vec<Element> { | ||
self.model | ||
.companies | ||
.values() | ||
.map(|company| self.export_company(company)) | ||
.collect() | ||
} | ||
} | ||
|
||
// Internal methods | ||
impl<'a> CompanyExporter<'a> { | ||
fn export_company(&self, company: &'a Company) -> Element { | ||
let element_builder = Element::builder(ObjectType::Operator.to_string()) | ||
.attr( | ||
"id", | ||
Exporter::generate_id(&company.id, ObjectType::Operator), | ||
) | ||
.attr("version", "any"); | ||
let element_builder = element_builder.append(self.generate_name(company)); | ||
let element_builder = element_builder.append(self.generate_contact_details(company)); | ||
let element_builder = element_builder.append(Self::generate_organization_type()); | ||
element_builder.build() | ||
} | ||
|
||
fn generate_name(&self, company: &'a Company) -> Element { | ||
Element::builder("Name") | ||
.append(Node::Text(company.name.to_owned())) | ||
.build() | ||
} | ||
|
||
fn generate_contact_details(&self, company: &'a Company) -> Element { | ||
let element_builder = Element::builder("ContactDetails"); | ||
let element_builder = if let Some(email_element) = self.generate_email(company) { | ||
element_builder.append(email_element) | ||
} else { | ||
element_builder | ||
}; | ||
let element_builder = if let Some(phone_element) = self.generate_phone(company) { | ||
element_builder.append(phone_element) | ||
} else { | ||
element_builder | ||
}; | ||
let element_builder = if let Some(url_element) = self.generate_url(company) { | ||
element_builder.append(url_element) | ||
} else { | ||
element_builder | ||
}; | ||
element_builder.build() | ||
} | ||
|
||
fn generate_email(&self, company: &'a Company) -> Option<Element> { | ||
company.mail.as_ref().map(|email| { | ||
Element::builder("Email") | ||
.append(Node::Text(email.to_owned())) | ||
.build() | ||
}) | ||
} | ||
|
||
fn generate_phone(&self, company: &'a Company) -> Option<Element> { | ||
company.phone.as_ref().map(|phone| { | ||
Element::builder("Phone") | ||
.append(Node::Text(phone.to_owned())) | ||
.build() | ||
}) | ||
} | ||
|
||
fn generate_url(&self, company: &'a Company) -> Option<Element> { | ||
company.url.as_ref().map(|url| { | ||
Element::builder("Url") | ||
.append(Node::Text(url.to_owned())) | ||
.build() | ||
}) | ||
} | ||
|
||
fn generate_organization_type() -> Element { | ||
Element::builder("OrganisationType") | ||
.append(Node::Text(String::from("other"))) | ||
.build() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
agency_id,agency_name,agency_url,agency_timezone,agency_lang,agency_phone,agency_email | ||
TGN,The Great Network,http://www.navitia.io/,Europe/Paris,,, | ||
TGN,The Great Network,https://www.the-great-network.zz,Europe/Paris,,0123456789,[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
company_id,company_name | ||
TGC,The Great Company | ||
company_id,company_name,company_mail,company_phone,company_url | ||
TGN,The Great Network,[email protected],0123456789,https://www.the-great-network.zz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
route_id,service_id,trip_id,company_id,physical_mode_id,dataset_id | ||
M1F,Week,M1F1,TGC,Metro,TGDS | ||
M1B,Week,M1B1,TGC,Metro,TGDS | ||
B42F,Week,B42F1,TGC,Bus,TGDS | ||
B42B,Week,B42B1,TGC,Bus,TGDS | ||
RERAF,Week,RERAF1,TGC,RapidTransit,TGDS | ||
RERAB,Week,RERAB1,TGC,Bus,TGDS | ||
M1F,Week,M1F1,TGN,Metro,TGDS | ||
M1B,Week,M1B1,TGN,Metro,TGDS | ||
B42F,Week,B42F1,TGN,Bus,TGDS | ||
B42B,Week,B42B1,TGN,Bus,TGDS | ||
RERAF,Week,RERAF1,TGN,RapidTransit,TGDS | ||
RERAB,Week,RERAB1,TGN,Bus,TGDS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,19 @@ | |
</Line> | ||
</lines> | ||
</ServiceFrame> | ||
<ResourceFrame id="FR:ResourceFrame:operators:" version="any"> | ||
<organisations> | ||
<Operator id="FR:Operator:TGN:" version="any"> | ||
<Name>The Great Network</Name> | ||
<ContactDetails> | ||
<Email>[email protected]</Email> | ||
<Phone>0123456789</Phone> | ||
<Url>https://www.the-great-network.zz</Url> | ||
</ContactDetails> | ||
<OrganisationType>other</OrganisationType> | ||
</Operator> | ||
</organisations> | ||
</ResourceFrame> | ||
</frames> | ||
</CompositeFrame> | ||
</dataObjects> | ||
|