mod calendars;
use calendars::CalendarExporter;
mod companies;
use companies::CompanyExporter;
mod exporter;
use exporter::Exporter;
mod lines;
use lines::LineExporter;
use lines::LineModes;
mod modes;
use modes::NetexMode;
mod networks;
use networks::NetworkExporter;
mod offer;
use offer::OfferExporter;
mod route_points;
use route_points::build_route_points;
mod stops;
use stops::StopExporter;
mod transfers;
use transfers::TransferExporter;
use crate::{model::Model, Result};
use chrono::{DateTime, FixedOffset};
pub struct WriteConfiguration {
participant: String,
stop_provider: Option<String>,
current_datetime: DateTime<FixedOffset>,
}
impl WriteConfiguration {
pub fn new<S: Into<String>>(participant: S) -> Self {
WriteConfiguration {
participant: participant.into(),
stop_provider: None,
current_datetime: chrono::Utc::now().with_timezone(&FixedOffset::east_opt(0).unwrap()),
}
}
pub fn stop_provider<S: Into<String>>(self, stop_provider: S) -> Self {
WriteConfiguration {
stop_provider: Some(stop_provider.into()),
..self
}
}
pub fn current_datetime(self, current_datetime: DateTime<FixedOffset>) -> Self {
WriteConfiguration {
current_datetime,
..self
}
}
}
pub fn write<P: AsRef<std::path::Path>>(
model: &Model,
path: P,
config: WriteConfiguration,
) -> Result<()> {
let exporter = Exporter::new(
model,
config.participant,
config.stop_provider,
config.current_datetime,
);
exporter.write(path)?;
Ok(())
}
pub fn write_to_zip<P: AsRef<std::path::Path>>(
model: &Model,
path: P,
config: WriteConfiguration,
) -> Result<()> {
let output_dir = tempfile::tempdir()?;
write(model, output_dir.path(), config)?;
crate::utils::zip_to(output_dir.path(), path)?;
output_dir.close()?;
Ok(())
}