Skip to content

Commit

Permalink
feat(core): add mapping for status change
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 13, 2021
1 parent f6aab5d commit 9541151
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
2 changes: 0 additions & 2 deletions quake_core/src/entry/entry_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ impl EntryFile {
pub struct ValueConverter {}

impl ValueConverter {
// (?P<time>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2})\s"(?P<start>.*)"\s->\s"(?P<end>.*)"
//
pub fn changing(value: Value) -> Vec<String> {
match value {
Value::Sequence(seq) => seq
Expand Down
41 changes: 41 additions & 0 deletions quake_core/src/meta/quake_changing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
use lazy_static::lazy_static;
use regex::Regex;

lazy_static! {
static ref STATUS_CHANGE: Regex = Regex::new(
r#"(?P<time>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2})\s"(?P<from>.*)" -> "(?P<to>.*)""#
)
.unwrap();
}

#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct QuakeChanging {
pub from: String,
pub to: String,
pub changed_date: String,
}

impl QuakeChanging {
pub fn from(text: &str) -> QuakeChanging {
match STATUS_CHANGE.captures(text) {
None => QuakeChanging {
from: "".to_string(),
to: "".to_string(),
changed_date: "".to_string(),
},
Some(caps) => QuakeChanging {
from: caps["from"].to_string(),
to: caps["to"].to_string(),
changed_date: caps["time"].to_string(),
},
}
}
}

#[cfg(test)]
mod tests {
use crate::meta::quake_changing::QuakeChanging;

#[test]
fn from_string() {
let text = "2021-12-09 09:40:28 \"Spike\" -> \"Todo\"";
let changing = QuakeChanging::from(text);
assert_eq!("2021-12-09 09:40:28", changing.changed_date);
assert_eq!("Spike", changing.from);
assert_eq!("Todo", changing.to);
}
}

0 comments on commit 9541151

Please sign in to comment.