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

Manage pathways refactoring #4

Merged
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
2 changes: 1 addition & 1 deletion src/gtfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ where
collections.comments = comments;
read::manage_stop_times(&mut collections, file_handler)?;
read::manage_frequencies(&mut collections, file_handler)?;
collections.pathways = read::read_pathways(&mut collections, file_handler)?;
read::manage_pathways(&mut collections, file_handler)?;
collections.levels = read_utils::read_opt_collection(file_handler, "levels.txt")?;
collections.sanitize()?;

Expand Down
13 changes: 5 additions & 8 deletions src/gtfs/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,10 +675,7 @@ where
Ok((stopareas, stoppoints, stoplocations))
}

pub fn read_pathways<H>(
collections: &mut Collections,
file_handler: &mut H,
) -> Result<CollectionWithId<objects::Pathway>>
pub fn manage_pathways<H>(collections: &mut Collections, file_handler: &mut H) -> Result<()>
where
for<'a> &'a mut H: FileHandler,
{
Expand All @@ -687,7 +684,6 @@ where
match reader {
None => {
info!("Skipping {}", file);
Ok(CollectionWithId::new(vec![])?)
}
Some(reader) => {
info!("Reading {}", file);
Expand Down Expand Up @@ -729,9 +725,10 @@ where
}));
pathways.push(pathway);
}
Ok(CollectionWithId::new(pathways)?)
collections.pathways = CollectionWithId::new(pathways)?;
}
}
Ok(())
}

pub fn read_transfers<H>(
Expand Down Expand Up @@ -3026,8 +3023,8 @@ mod tests {
collections.stop_points = stop_points;
collections.stop_locations = stop_locations;

let pathways = super::read_pathways(&mut collections, &mut handler).unwrap();
assert_eq!(1, pathways.len());
super::manage_pathways(&mut collections, &mut handler).unwrap();
assert_eq!(1, collections.pathways.len());
})
}
#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/ntfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub fn read<P: AsRef<path::Path>>(path: P) -> Result<Model> {
read::manage_geometries(&mut collections, path)?;
read::manage_feed_infos(&mut collections, path)?;
read::manage_stops(&mut collections, path)?;
collections.pathways = read::read_pathways(&mut collections, path)?;
read::manage_pathways(&mut collections, path)?;
read::manage_stop_times(&mut collections, path)?;
read::manage_codes(&mut collections, path)?;
read::manage_comments(&mut collections, path)?;
Expand Down
10 changes: 4 additions & 6 deletions src/ntfs/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,15 +618,12 @@ pub fn manage_companies_on_vj(collections: &mut Collections) -> Result<()> {
Ok(())
}

pub fn read_pathways(
collections: &mut Collections,
path: &path::Path,
) -> Result<CollectionWithId<Pathway>> {
pub fn manage_pathways(collections: &mut Collections, path: &path::Path) -> Result<()> {
let file = "pathways.txt";
let pathway_path = path.join(file);
if !pathway_path.exists() {
info!("Skipping {}", file);
return Ok(CollectionWithId::new(vec![])?);
return Ok(());
}

info!("Reading {}", file);
Expand Down Expand Up @@ -671,7 +668,8 @@ pub fn read_pathways(
pathways.push(pathway);
}

Ok(CollectionWithId::new(pathways)?)
collections.pathways = CollectionWithId::new(pathways)?;
Ok(())
}

#[cfg(test)]
Expand Down