Skip to content

Commit

Permalink
Merge pull request #4 from ArnaudOggy/update_gtfs_parser
Browse files Browse the repository at this point in the history
Manage pathways refactoring
  • Loading branch information
patochectp authored Oct 15, 2019
2 parents 8d9037a + b60f26f commit bf086d9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
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 @@ -676,10 +676,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 @@ -688,7 +685,6 @@ where
match reader {
None => {
info!("Skipping {}", file);
Ok(CollectionWithId::new(vec![])?)
}
Some(reader) => {
info!("Reading {}", file);
Expand Down Expand Up @@ -730,9 +726,10 @@ where
}));
pathways.push(pathway);
}
Ok(CollectionWithId::new(pathways)?)
collections.pathways = CollectionWithId::new(pathways)?;
}
}
Ok(())
}

pub fn read_transfers<H>(
Expand Down Expand Up @@ -3035,8 +3032,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

0 comments on commit bf086d9

Please sign in to comment.