diff --git a/plate-tool-lib/src/csv/mangle_headers.rs b/plate-tool-lib/src/csv/mangle_headers.rs index b9a1691..6c1d9ad 100644 --- a/plate-tool-lib/src/csv/mangle_headers.rs +++ b/plate-tool-lib/src/csv/mangle_headers.rs @@ -5,6 +5,8 @@ pub fn mangle_headers(data: &str) -> String { for field in fields { if let Some(f) = detect_field(field) { modified_headers.push(f.to_string()); + } else { + log::debug!("Unk field: {:?}", field) } } @@ -12,22 +14,25 @@ pub fn mangle_headers(data: &str) -> String { } fn detect_field(field: &str) -> Option { + // NOTE: Don't return none! Consider refactor to -> Field later on. + // Returning none means a field will be dropped, which requires the user to manually drop + // columns from their picklist. match field.trim().to_lowercase() { x if x.contains("source") || x.contains("src") => match x { - _ if x.contains("plate") => Some(Field::SourcePlate), + _ if x.contains("plate") || x.contains("barcode") => Some(Field::SourcePlate), _ if x.contains("well") => Some(Field::SourceWell), _ if x.contains("format") || x.contains("fmt") => Some(Field::SourceFormat), - _ => None, + _ => Some(Field::Other(x)), // Retain unknown fields }, x if x.contains("destination") || x.contains("dest") => match x { - _ if x.contains("plate") => Some(Field::DestinationPlate), + _ if x.contains("plate") || x.contains("barcode") => Some(Field::DestinationPlate), _ if x.contains("well") => Some(Field::DestinationWell), _ if x.contains("format") || x.contains("fmt") => Some(Field::DestinationFormat), - _ => None, + _ => Some(Field::Other(x)), // Retain unknown fields }, x if x.contains("volume") => Some(Field::Volume), x if x.contains("concentration") => Some(Field::Concentration), - _ => None, + x => Some(Field::Other(x)), // Retain unknown fields } } @@ -40,6 +45,7 @@ enum Field { DestinationFormat, Volume, Concentration, + Other(String), } impl ToString for Field { @@ -53,6 +59,7 @@ impl ToString for Field { Field::DestinationFormat => "destinationformat".to_string(), Field::Volume => "volume".to_string(), Field::Concentration => "concentration".to_string(), + Field::Other(x) => x.to_string(), } } }