Use an enum for the episode marker rule failure reasons
This commit is contained in:
parent
afd3c527f2
commit
2937e98988
2 changed files with 38 additions and 11 deletions
|
@ -8,39 +8,39 @@ impl Rule for EpisodeMarker {
|
|||
match captures.name("seasonPrefix") {
|
||||
Some(marker) => {
|
||||
if marker.as_str() != "S" {
|
||||
return Some(NonCompliantReason::InvalidEpisodeMarker("Season Prefix must be 'S'".to_string()))
|
||||
return Some(NonCompliantReason::InvalidEpisodeMarker(EpisodeMarkerReason::SeasonPrefix))
|
||||
}
|
||||
}
|
||||
None => return Some(NonCompliantReason::InvalidEpisodeMarker("No Season Prefix found".to_string())),
|
||||
None => return Some(NonCompliantReason::InvalidEpisodeMarker(EpisodeMarkerReason::MissingSeasonPrefix)),
|
||||
}
|
||||
|
||||
match captures.name("episodePrefix") {
|
||||
Some(marker) => {
|
||||
if marker.as_str() != "E" {
|
||||
return Some(NonCompliantReason::InvalidEpisodeMarker("Episode Prefix must be 'E'".to_string()))
|
||||
return Some(NonCompliantReason::InvalidEpisodeMarker(EpisodeMarkerReason::EpisodePrefix))
|
||||
}
|
||||
}
|
||||
None => return Some(NonCompliantReason::InvalidEpisodeMarker("No Episode Prefix found".to_string())),
|
||||
None => return Some(NonCompliantReason::InvalidEpisodeMarker(EpisodeMarkerReason::MissingEpisodePrefix)),
|
||||
}
|
||||
|
||||
match captures.name("season") {
|
||||
Some(marker) => {
|
||||
let str = marker.as_str();
|
||||
if str.len() != 2 && str.len() != 3 {
|
||||
return Some(NonCompliantReason::InvalidEpisodeMarker("Season should be annotated with either 2 or 3 digits".to_string()))
|
||||
return Some(NonCompliantReason::InvalidEpisodeMarker(EpisodeMarkerReason::SeasonDigits))
|
||||
}
|
||||
}
|
||||
None => return Some(NonCompliantReason::InvalidEpisodeMarker("No Season digits found".to_string())),
|
||||
None => return Some(NonCompliantReason::InvalidEpisodeMarker(EpisodeMarkerReason::MissingSeasonDigits)),
|
||||
}
|
||||
|
||||
match captures.name("episode") {
|
||||
Some(marker) => {
|
||||
let str = marker.as_str();
|
||||
if str.len() != 2 && str.len() != 3 {
|
||||
return Some(NonCompliantReason::InvalidEpisodeMarker("Episode should be annotated with either 2 or 3 digits".to_string()))
|
||||
return Some(NonCompliantReason::InvalidEpisodeMarker(EpisodeMarkerReason::EpisodeDigits))
|
||||
}
|
||||
}
|
||||
None => return Some(NonCompliantReason::InvalidEpisodeMarker("No Episode digits found".to_string())),
|
||||
None => return Some(NonCompliantReason::InvalidEpisodeMarker(EpisodeMarkerReason::MissingEpisodeDigits)),
|
||||
}
|
||||
|
||||
return None
|
||||
|
@ -53,7 +53,7 @@ impl Rule for EpisodeMarker {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::rules::{NonCompliantReason, Rule};
|
||||
use crate::rules::{NonCompliantReason, EpisodeMarkerReason, Rule};
|
||||
use crate::SERIES_REGEX;
|
||||
|
||||
#[test]
|
||||
|
@ -67,6 +67,6 @@ mod tests {
|
|||
fn no_dash() {
|
||||
let title = "Test S00x00.mkv";
|
||||
let captures = regex::Regex::new(SERIES_REGEX).unwrap().captures(title).unwrap();
|
||||
assert_eq!(super::EpisodeMarker::check(title, &captures), Some(NonCompliantReason::InvalidEpisodeMarker("Episode Prefix must be 'E'".to_string())));
|
||||
assert_eq!(super::EpisodeMarker::check(title, &captures), Some(NonCompliantReason::InvalidEpisodeMarker(EpisodeMarkerReason::EpisodePrefix)));
|
||||
}
|
||||
}
|
|
@ -20,7 +20,7 @@ pub enum NonCompliantReason {
|
|||
MissingName,
|
||||
HasFluff,
|
||||
MissingNameSeparator,
|
||||
InvalidEpisodeMarker(String)
|
||||
InvalidEpisodeMarker(EpisodeMarkerReason)
|
||||
}
|
||||
|
||||
impl Display for NonCompliantReason {
|
||||
|
@ -35,6 +35,33 @@ impl Display for NonCompliantReason {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum EpisodeMarkerReason {
|
||||
SeasonPrefix,
|
||||
MissingSeasonPrefix,
|
||||
EpisodePrefix,
|
||||
MissingEpisodePrefix,
|
||||
SeasonDigits,
|
||||
MissingSeasonDigits,
|
||||
EpisodeDigits,
|
||||
MissingEpisodeDigits
|
||||
}
|
||||
|
||||
impl Display for EpisodeMarkerReason {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
EpisodeMarkerReason::SeasonPrefix => write!(f, "Season Prefix must be 'S'"),
|
||||
EpisodeMarkerReason::MissingSeasonPrefix => write!(f, "No Season Prefix found"),
|
||||
EpisodeMarkerReason::EpisodePrefix => write!(f, "Episode Prefix must be 'E'"),
|
||||
EpisodeMarkerReason::MissingEpisodePrefix => write!(f, "No Episode Prefix found"),
|
||||
EpisodeMarkerReason::SeasonDigits => write!(f, "Season should be annotated with either 2 or 3 digits"),
|
||||
EpisodeMarkerReason::MissingSeasonDigits => write!(f, "No Season digits found"),
|
||||
EpisodeMarkerReason::EpisodeDigits => write!(f, "Episode should be annotated with either 2 or 3 digits"),
|
||||
EpisodeMarkerReason::MissingEpisodeDigits => write!(f, "No Episode digits found"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ComplianceStatus {
|
||||
NonCompliant(NonCompliantReason),
|
||||
NotMatched,
|
||||
|
|
Loading…
Reference in a new issue