use std::collections::HashMap;
#[derive(Debug, Default)]
pub struct MarkdownCapture {
files: HashMap<String, String>,
}
impl MarkdownCapture {
#[must_use]
pub fn new() -> Self {
Self {
files: HashMap::new(),
}
}
pub fn insert(&mut self, path: String, content: String) {
self.files.insert(path, content);
}
#[must_use]
pub fn get(&self, path: &str) -> Option<&String> {
self.files.get(path)
}
#[must_use]
pub fn paths(&self) -> Vec<&String> {
let mut paths: Vec<_> = self.files.keys().collect();
paths.sort();
paths
}
#[must_use]
pub fn len(&self) -> usize {
self.files.len()
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.files.is_empty()
}
#[must_use]
pub fn to_snapshot_string(&self) -> String {
use std::fmt::Write;
let mut result = String::new();
let mut paths: Vec<_> = self.files.keys().collect();
paths.sort();
for path in paths {
_ = writeln!(result, "=== {path} ===");
_ = write!(result, "{}", &self.files[path]);
if !self.files[path].ends_with('\n') {
result.push('\n');
}
result.push('\n');
}
result
}
#[must_use]
pub fn into_inner(self) -> HashMap<String, String> {
self.files
}
}