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") {
|
match captures.name("seasonPrefix") {
|
||||||
Some(marker) => {
|
Some(marker) => {
|
||||||
if marker.as_str() != "S" {
|
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") {
|
match captures.name("episodePrefix") {
|
||||||
Some(marker) => {
|
Some(marker) => {
|
||||||
if marker.as_str() != "E" {
|
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") {
|
match captures.name("season") {
|
||||||
Some(marker) => {
|
Some(marker) => {
|
||||||
let str = marker.as_str();
|
let str = marker.as_str();
|
||||||
if str.len() != 2 && str.len() != 3 {
|
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") {
|
match captures.name("episode") {
|
||||||
Some(marker) => {
|
Some(marker) => {
|
||||||
let str = marker.as_str();
|
let str = marker.as_str();
|
||||||
if str.len() != 2 && str.len() != 3 {
|
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
|
return None
|
||||||
|
@ -53,7 +53,7 @@ impl Rule for EpisodeMarker {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::rules::{NonCompliantReason, Rule};
|
use crate::rules::{NonCompliantReason, EpisodeMarkerReason, Rule};
|
||||||
use crate::SERIES_REGEX;
|
use crate::SERIES_REGEX;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -67,6 +67,6 @@ mod tests {
|
||||||
fn no_dash() {
|
fn no_dash() {
|
||||||
let title = "Test S00x00.mkv";
|
let title = "Test S00x00.mkv";
|
||||||
let captures = regex::Regex::new(SERIES_REGEX).unwrap().captures(title).unwrap();
|
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,
|
MissingName,
|
||||||
HasFluff,
|
HasFluff,
|
||||||
MissingNameSeparator,
|
MissingNameSeparator,
|
||||||
InvalidEpisodeMarker(String)
|
InvalidEpisodeMarker(EpisodeMarkerReason)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for NonCompliantReason {
|
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 {
|
pub enum ComplianceStatus {
|
||||||
NonCompliant(NonCompliantReason),
|
NonCompliant(NonCompliantReason),
|
||||||
NotMatched,
|
NotMatched,
|
||||||
|
|
Loading…
Reference in a new issue