diff options
author | Daniel <kingdread@gmx.de> | 2018-09-10 00:40:29 +0200 |
---|---|---|
committer | Daniel <kingdread@gmx.de> | 2018-09-10 00:40:29 +0200 |
commit | 2c1203f6f2c3e6bbaf527fa202425ed465e89d69 (patch) | |
tree | f0cd60ed0e58044738b054fc8120972f213a4e43 | |
parent | ab639eea67e830ab27f51adb2665c73d93c682c7 (diff) | |
download | raidgrep-2c1203f6f2c3e6bbaf527fa202425ed465e89d69.tar.gz raidgrep-2c1203f6f2c3e6bbaf527fa202425ed465e89d69.tar.bz2 raidgrep-2c1203f6f2c3e6bbaf527fa202425ed465e89d69.zip |
move filtering into own submodule
-rw-r--r-- | src/filters.rs | 33 | ||||
-rw-r--r-- | src/main.rs | 36 |
2 files changed, 42 insertions, 27 deletions
diff --git a/src/filters.rs b/src/filters.rs new file mode 100644 index 0000000..1549c26 --- /dev/null +++ b/src/filters.rs @@ -0,0 +1,33 @@ +use evtclib::{AgentName, Log}; + +use super::{LogResult, Opt}; + +/// Do filtering based on the character or account name. +pub fn filter_name(log: &Log, opt: &Opt) -> bool { + for player in log.players() { + match player.name() { + AgentName::Player { + account_name, + character_name, + .. + } => { + if (opt.field.search_account() && opt.expression.is_match(account_name)) + || (opt.field.search_character() && opt.expression.is_match(character_name)) + { + return true; + } + } + _ => unreachable!(), + } + } + return false; +} + +/// Do filtering based on the fight outcome. +pub fn filter_outcome(result: &LogResult, opt: &Opt) -> bool { + match opt.outcome { + Some(o) if o == result.outcome => true, + None => true, + _ => false, + } +} diff --git a/src/main.rs b/src/main.rs index 9343e14..2e3007c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,11 +27,13 @@ use errors::RuntimeError; mod output; +mod filters; + /// A program that allows you to search through all your evtc logs for specific /// people. #[derive(StructOpt, Debug)] #[structopt(name = "raidgrep")] -struct Opt { +pub struct Opt { /// Path to the folder with logs. #[structopt( short = "d", @@ -207,34 +209,14 @@ fn search_log(entry: &DirEntry, opt: &Opt) -> Result<Option<LogResult>, RuntimeE return Ok(None); }; - let mut candidate_good = false; - for player in log.players() { - match player.name() { - AgentName::Player { - account_name, - character_name, - .. - } => { - if (opt.field.search_account() && opt.expression.is_match(account_name)) - || (opt.field.search_character() && opt.expression.is_match(character_name)) - { - candidate_good = true; - } - } - _ => unreachable!(), - } - } - - if !candidate_good { - return Ok(None); - } + let info = extract_info(entry, &log); - let result = extract_info(entry, &log); + let take_log = filters::filter_name(&log, opt) && filters::filter_outcome(&info, opt); - match opt.outcome { - Some(o) if o == result.outcome => Ok(Some(result)), - None => Ok(Some(result)), - _ => Ok(None), + if take_log { + Ok(Some(info)) + } else { + Ok(None) } } |