This commit is contained in:
philipp 2023-11-06 23:53:59 +01:00
parent ec91de2eae
commit 1d37ad192f
2 changed files with 6 additions and 56 deletions

View File

@ -1,4 +1,4 @@
use log::{debug, error, info};
use log::{debug, info};
use serde::{Deserialize, Serialize};
use std::{
cell::RefCell,
@ -20,7 +20,7 @@ impl Law {
println!("# {}", self.name);
for header in &self.header {
Self::print_md(&header, 2);
Self::print_md(header, 2);
}
}
@ -29,7 +29,7 @@ impl Law {
match &header.content {
HeadingContent::Heading(h) => {
for child in h {
Self::print_md(&child, level + 1);
Self::print_md(child, level + 1);
}
}
HeadingContent::Paragraph(p) => {
@ -102,27 +102,6 @@ impl From<ClassifierInstance> for HeadingContent {
}
}
fn add_from_node(cur: &ClassifierInstance, builder: &LawBuilder) -> Heading {
let children = builder.get_by_parent(&cur.name);
if !children.is_empty() {
let mut ret = Vec::new();
for child in children {
ret.push(add_from_node(&child, builder));
}
Heading {
name: cur.name.clone(),
desc: cur.desc.clone(),
content: HeadingContent::Heading(ret),
}
} else {
Heading {
name: cur.name.clone(),
desc: cur.desc.clone(),
content: HeadingContent::Paragraph(cur.sections.clone()),
}
}
}
pub(crate) fn contains(classifier_name: &str, instance_name: &str) -> bool {
instance_name
.to_lowercase()
@ -174,6 +153,7 @@ impl PartialEq for LawBuilder {
}
impl LawBuilder {
#[cfg(test)]
pub(crate) fn test(name: &str) -> Self {
let mut classifiers = Vec::new();
@ -235,12 +215,7 @@ impl LawBuilder {
}
fn responsible_classifier(&self, name: &str) -> Option<&Classifier> {
for c in &self.classifiers {
if c.used_for(name) {
return Some(&c);
}
}
None
self.classifiers.iter().find(|&c| c.used_for(name))
}
fn find_parent(
@ -356,22 +331,6 @@ impl LawBuilder {
debug!("new_next_para_header={header}");
self.next_para_header = Some(header.trim().into());
}
fn get_by_parent(&self, name: &String) -> Vec<ClassifierInstance> {
let mut ret = Vec::new();
// for class in &self.classifiers {
// for inst in &class.instances {
// if let Some(parent) = &inst.parent {
// if &parent.name == name {
// ret.push(inst.clone());
// }
// }
// }
// }
ret
}
}
#[derive(Clone, PartialEq, Serialize, Deserialize)]
@ -383,7 +342,7 @@ pub(crate) struct Section {
impl fmt::Debug for Section {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let par_header = self.par_header.as_ref().map(String::as_str).unwrap_or("");
let par_header = self.par_header.as_deref().unwrap_or("");
write!(f, "{} ({})", self.symb, par_header)
}
}
@ -489,14 +448,6 @@ impl Classifier {
fn used_for(&self, name: &str) -> bool {
(self.used_for_fn)(&self.name, name)
}
pub(crate) fn add_child(&mut self, child: Rc<RefCell<Classifier>>) {
self.child.push(child);
}
pub(crate) fn add_instance(&mut self, instance: ClassifierInstance) {
self.instances.push(instance);
}
}
impl std::fmt::Debug for Classifier {

View File

@ -1,4 +1,3 @@
use log::{error, info};
use roxmltree::Node;
use crate::{