From b9781c01905a3fb724dd54fc24b8f07c84bb46a8 Mon Sep 17 00:00:00 2001 From: PoiScript Date: Wed, 30 Oct 2019 11:59:20 +0800 Subject: [PATCH] feat(elements): Title::is_commented --- src/elements/title.rs | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/src/elements/title.rs b/src/elements/title.rs index 0814651..7969c94 100644 --- a/src/elements/title.rs +++ b/src/elements/title.rs @@ -57,37 +57,34 @@ impl Title<'_> { parse_title::<()>(input, config).ok() } - // TODO: fn is_archived(&self) -> bool { } - // TODO: fn is_commented(&self) -> bool { } // TODO: fn is_quoted(&self) -> bool { } // TODO: fn is_footnote_section(&self) -> bool { } /// Returns this headline's closed timestamp, or `None` if not set. pub fn closed(&self) -> Option<&Timestamp> { - self.planning - .as_ref() - .and_then(|planning| planning.closed.as_ref()) + self.planning.and_then(|p| p.closed.as_ref()) } /// Returns this headline's scheduled timestamp, or `None` if not set. pub fn scheduled(&self) -> Option<&Timestamp> { - self.planning - .as_ref() - .and_then(|planning| planning.scheduled.as_ref()) + self.planning.and_then(|p| p.scheduled.as_ref()) } /// Returns this headline's deadline timestamp, or `None` if not set. pub fn deadline(&self) -> Option<&Timestamp> { - self.planning - .as_ref() - .and_then(|planning| planning.deadline.as_ref()) + self.planning.and_then(|p| p.deadline.as_ref()) } - /// checks if this headline is "archived" + /// Returns `true` if this headline is archived pub fn is_archived(&self) -> bool { self.tags.iter().any(|tag| tag == "ARCHIVE") } + /// Returns `true` if this headline is commented + pub fn is_commented(&self) -> bool { + self.raw.starts_with("COMMENT ") + } + pub fn into_owned(self) -> Title<'static> { Title { level: self.level, @@ -433,17 +430,3 @@ fn parse_properties_drawer_() { )) ) } - -// #[test] -// fn is_commented() { -// assert!(parse_title::>("* COMMENT Title", &DEFAULT_CONFIG) -// .1 -// .is_commented()); -// assert!(!parse_title::>("* Title", &DEFAULT_CONFIG).1.is_commented()); -// assert!(!parse_title::>("* C0MMENT Title", &DEFAULT_CONFIG) -// .1 -// .is_commented()); -// assert!(!parse_title::>("* comment Title", &DEFAULT_CONFIG) -// .1 -// .is_commented()); -// }