use std::path::Path;
use crate::reader::{is_modat_file, is_moflo_file};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum FileFormat {
Modat,
Dat,
Dax,
Modax,
Moflo,
Csv,
Json,
}
impl FileFormat {
pub fn from_path(path: &Path) -> Option<Self> {
if is_modat_file(path) {
Some(Self::Modat)
} else if is_moflo_file(path) {
Some(Self::Moflo)
} else {
path.extension().and_then(|ext| ext.to_str()).and_then(|ext| {
match ext.to_ascii_lowercase().as_str() {
"dat" => Some(Self::Dat),
"dax" => Some(Self::Dax),
"modax" => Some(Self::Modax),
"csv" => Some(Self::Csv),
"json" => Some(Self::Json),
_ => None,
}
})
}
}
pub fn extension(self) -> &'static str {
match self {
Self::Modat => "modat",
Self::Dat => "dat",
Self::Dax => "dax",
Self::Modax => "modax",
Self::Moflo => "moflo",
Self::Csv => "csv",
Self::Json => "json",
}
}
pub fn is_readable(self) -> bool {
matches!(self, Self::Modat | Self::Dat | Self::Dax | Self::Modax | Self::Moflo)
}
pub fn is_writable(self) -> bool {
matches!(self, Self::Modat | Self::Csv | Self::Json)
}
pub fn is_waveform(self) -> bool {
matches!(self, Self::Modat | Self::Dat | Self::Dax | Self::Modax)
}
}