use super::stereo_chemical_props;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) enum Converter {
Tsv,
StereoChemicalProps,
}
impl Converter {
pub(super) fn named(id: &str) -> Result<Self, String> {
match id {
"tsv" => Ok(Self::Tsv),
"stereo_chemical_props" => Ok(Self::StereoChemicalProps),
other => Err(format!(
"unknown converter `{other}`; use tsv or stereo_chemical_props"
)),
}
}
pub(super) fn rows(self, text: &str) -> Result<Vec<String>, String> {
match self {
Self::Tsv => Ok(tab_rows(text)),
Self::StereoChemicalProps => stereo_chemical_props::rows(text),
}
}
}
fn tab_rows(text: &str) -> Vec<String> {
text.lines()
.map(str::trim)
.filter(|line| !line.is_empty() && !line.starts_with('#'))
.map(str::to_owned)
.collect()
}
#[cfg(test)]
#[path = "convert_tests.rs"]
mod tests;