Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Add DayType for NeTEx France #535

Merged
merged 1 commit into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions src/netex_france/calendars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@

use crate::{objects::Calendar, Model, Result};
use minidom::Element;
use std::fmt::{self, Display, Formatter};

enum ObjectType {
DayType,
}

impl Display for ObjectType {
fn fmt(&self, f: &mut Formatter) -> std::result::Result<(), fmt::Error> {
use ObjectType::*;
match self {
DayType => write!(f, "DayType"),
}
}
}

pub struct CalendarExporter<'a> {
model: &'a Model,
Expand All @@ -25,7 +39,7 @@ impl<'a> CalendarExporter<'a> {
CalendarExporter { model }
}
pub fn export(&self) -> Result<Vec<Element>> {
let _day_types_elements = self
let day_types_elements = self
.model
.calendars
.values()
Expand All @@ -43,9 +57,7 @@ impl<'a> CalendarExporter<'a> {
.values()
.map(|calendar| self.export_uic_operating_period(calendar))
.collect::<Result<Vec<Element>>>()?;
let elements = Vec::new();
// TODO: Uncomment below once implemented
// let mut elements = day_types_elements;
let elements = day_types_elements;
// elements.extend(day_type_assignments_elements);
// elements.extend(uic_operating_periods_elements);
Ok(elements)
Expand All @@ -54,9 +66,11 @@ impl<'a> CalendarExporter<'a> {

// Internal methods
impl<'a> CalendarExporter<'a> {
fn export_day_type(&self, _calendar: &'a Calendar) -> Result<Element> {
let day_type = Element::builder("DayType").build();
Ok(day_type)
fn export_day_type(&self, calendar: &'a Calendar) -> Result<Element> {
let element_builder = Element::builder("DayType")
.attr("id", self.generate_id(&calendar.id, ObjectType::DayType))
.attr("version", "any");
Ok(element_builder.build())
}

fn export_day_type_assignement(&self, _calendar: &'a Calendar) -> Result<Element> {
Expand All @@ -68,4 +82,9 @@ impl<'a> CalendarExporter<'a> {
let uic_operating_period = Element::builder("UicOperatingPeriod").build();
Ok(uic_operating_period)
}

fn generate_id(&self, id: &'a str, object_type: ObjectType) -> String {
let id = id.replace(':', "_");
format!("FR:{}:{}:", object_type, id)
}
}
5 changes: 2 additions & 3 deletions src/netex_france/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,15 @@ impl Exporter<'_> {
fn create_calendars_frame(&self) -> Result<Element> {
let calendar_exporter = CalendarExporter::new(&self.model);
let calendars = calendar_exporter.export()?;
let _members = Self::create_members(calendars);
let members = Self::create_members(calendars);
let general_frame_id = self.generate_frame_id(
FrameType::General,
&format!("NETEX_{}", VersionType::Calendars),
);
let frame = Element::builder(FrameType::General.to_string())
.attr("id", general_frame_id)
.attr("version", "any")
// TODO: Uncomment once some members are created
// .append(members)
.append(members)
.build();
Ok(frame)
}
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/netex_france/calendriers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<ParticipantRef>Participant</ParticipantRef>
<dataObjects>
<GeneralFrame id="FR:GeneralFrame:NETEX_CALENDRIER:ProviderCode" version="any">
<members>
<DayType id="FR:DayType:Week:" version="any">
</DayType>
</members>
</GeneralFrame>
</dataObjects>
</PublicationDelivery>