use rhei_core::ast::{Task, TaskId, TaskIdSegment};
pub(crate) struct RheiGroup {
pub id: String,
pub title: String,
}
impl RheiGroup {
pub fn owns(&self, task: &Task) -> bool {
matches!(task.id.segments.first(), Some(TaskIdSegment::Named(name)) if *name == self.id)
}
pub fn section_title<'a>(&self, merged: &'a str) -> &'a str {
merged.strip_prefix(&format!("Rhei {} / ", self.id)).unwrap_or(merged)
}
pub fn heading(&self) -> String {
if self.title.eq_ignore_ascii_case(&self.id) {
self.title.clone()
} else {
format!("{} ({})", self.title, self.id)
}
}
}
pub(crate) fn rhei_groups(rhei: &rhei_core::ast::Rhei) -> Vec<RheiGroup> {
rhei.content_sections
.iter()
.filter_map(|section| {
let id = section.rhei.as_ref()?;
let title = section.title.strip_prefix(&format!("Rhei {id}: "))?;
Some(RheiGroup { id: id.clone(), title: title.to_string() })
})
.collect()
}
pub(crate) fn title_case_kind(kind: &str) -> String {
let mut out = String::with_capacity(kind.len());
let mut chars = kind.chars();
if let Some(first) = chars.next() {
for c in first.to_uppercase() {
out.push(c);
}
}
for c in chars {
out.push(c);
}
out
}
pub(crate) fn fmt_prior_list(ids: &[TaskId]) -> String {
ids.iter().map(|id| format!("Task {}", id)).collect::<Vec<String>>().join(", ")
}