use crate::reference::Reference;
use citum_schema::Style;
use citum_schema::locale::Locale;
use citum_schema::options::{Config, Substitute};
use std::borrow::Cow;
pub struct Matcher<'a> {
style: &'a Style,
config: &'a Config,
locale: &'a Locale,
}
impl<'a> Matcher<'a> {
#[must_use]
pub fn new(style: &'a Style, config: &'a Config, locale: &'a Locale) -> Self {
Self {
style,
config,
locale,
}
}
#[must_use]
pub fn contributors_match(&self, prev: &Reference, current: &Reference) -> bool {
let substitute = self.get_substitute_config();
let prev_names = crate::values::contributor::substitute::effective_primary_names(
prev,
substitute.as_ref(),
self.config,
self.locale,
);
let curr_names = crate::values::contributor::substitute::effective_primary_names(
current,
substitute.as_ref(),
self.config,
self.locale,
);
!prev_names.is_empty() && !curr_names.is_empty() && prev_names == curr_names
}
fn get_substitute_config(&self) -> Cow<'_, Substitute> {
if let Some(config) = self
.style
.options
.as_ref()
.and_then(|o| o.substitute.as_ref())
{
return config.resolve_ref();
}
self.config.substitute.as_ref().map_or_else(
|| Cow::Owned(Substitute::default()),
citum_schema::options::SubstituteConfig::resolve_ref,
)
}
}