use regex::Regex;
use crate::add::colspec::ColSpec;
pub struct Column {
colname: String,
}
impl Column {
pub fn with_name(name: &str) -> Column {
Column {
colname: name.into(),
}
}
pub fn from_all_previous(self) -> MixColumn {
MixColumn {
colname: self.colname,
}
}
pub fn from_column(self, name: &str) -> IncompleteRegexColumn {
IncompleteRegexColumn {
colname: self.colname,
source: name.into(),
}
}
}
pub struct MixColumn {
colname: String,
}
pub struct IncompleteRegexColumn {
colname: String,
source: String,
}
pub struct RegexColumn {
colname: String,
source: String,
regex: Regex,
}
impl MixColumn {
pub fn definition(self, def: &str) -> ColSpec {
ColSpec::Mix {
colname: self.colname,
coldef: def.into(),
}
}
}
impl IncompleteRegexColumn {
pub fn with_regex(self, regex: &str) -> Result<RegexColumn, regex::Error> {
Ok(RegexColumn {
colname: self.colname,
source: self.source,
regex: Regex::new(regex)?,
})
}
}
impl RegexColumn {
pub fn definition(self, def: &str) -> ColSpec {
ColSpec::Regex {
source: self.source,
colname: self.colname,
regex: self.regex,
coldef: def.into(),
}
}
}