This commit is contained in:
philipp 2023-11-04 14:18:26 +01:00
parent 11d55ed379
commit 5a238f6521
2 changed files with 37 additions and 22 deletions

View File

@ -19,6 +19,7 @@ pub(crate) struct LawBuilder {
name: String, //ABGB, UrhG
classifiers: Vec<Classifier>,
cur_classifier_index: Option<usize>,
next_para_header: Option<String>,
}
impl LawBuilder {
@ -37,6 +38,7 @@ impl LawBuilder {
name: name.into(),
classifiers,
cur_classifier_index: None,
next_para_header: None,
}
}
@ -59,6 +61,7 @@ impl LawBuilder {
name: name.into(),
classifiers,
cur_classifier_index: None,
next_para_header: None,
};
overview::parse(law_id.unwrap(), &mut builder);
@ -91,6 +94,10 @@ impl LawBuilder {
panic!("Expected at least one classifier");
}
}
pub(crate) fn new_next_para_header(&mut self, header: &str) {
self.next_para_header = Some(header.into());
}
}
pub(crate) struct Section {
@ -183,9 +190,9 @@ impl Classifier {
#[derive(Clone, Debug, PartialEq)]
pub(crate) enum Content {
Text(String), //This is my direct law text
Item((String, Box<Content>)), //(1) This is general law. (2) This is more specific law
List(Vec<Box<Content>>), //1. my first item
Text(String), //This is my direct law text
Item(Vec<Box<Content>>), //(1) This is general law. (2) This is more specific law
List(Vec<Box<Content>>), //1. my first item
}
#[cfg(test)]
@ -228,6 +235,7 @@ mod tests {
},
],
cur_classifier_index: Some(1),
next_para_header: Some("2. Abschnitt".into()),
};
assert_eq!(builder, expected);
}

View File

@ -2,7 +2,10 @@ use std::fmt::Display;
use roxmltree::Node;
use crate::{law::LawBuilder, Error};
use crate::{
law::{Content, LawBuilder},
Error,
};
#[derive(Debug, PartialEq)]
pub(crate) struct Risdok {
@ -38,9 +41,6 @@ impl Risdok {
impl Display for Risdok {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Some(par_header) = &self.nutzdaten.abschnitt.ueberschriftPara {
f.write_str(&format!("# {}", par_header.content))?;
}
for abs in &self.nutzdaten.abschnitt.absatze {
let mut w = String::new();
if let Some(symb) = &abs.gldsym {
@ -86,7 +86,6 @@ impl Nutzdaten {
#[derive(Debug, PartialEq)]
pub(crate) struct Abschnitt {
ueberschriftPara: Option<Ueberschrift>,
absatze: Vec<AbsatzAbs>,
}
impl Abschnitt {
@ -138,10 +137,10 @@ impl Abschnitt {
}
}
let mut ueberschriftPara = None;
if let Some(child) = c.peek() {
if Ueberschrift::test(child, "para") {
ueberschriftPara = Some(Ueberschrift::parse(c.next().unwrap(), "para"))
builder
.new_next_para_header(&Ueberschrift::parse(c.next().unwrap(), "para").content);
}
}
@ -159,6 +158,25 @@ impl Abschnitt {
}
}
if absatze.len() == 1 {
builder.new_par(Content::Text(format!(
"{} {}",
absatze[0].gldsym.clone().unwrap(),
absatze[0].content
)));
} else {
let mut content = Vec::new();
for a in &absatze {
let mut txt = String::new();
if let Some(sym) = &a.gldsym {
txt.push_str(&format!("{sym} "));
}
txt.push_str(&a.content);
content.push(Box::new(Content::Text(txt)));
}
builder.new_par(Content::Item(content));
}
// Skip all UeberschriftTitle and Absatz
loop {
match c.peek() {
@ -179,10 +197,7 @@ impl Abschnitt {
assert_eq!(c.next(), None);
Self {
ueberschriftPara,
absatze,
}
Self { absatze }
}
}
@ -335,10 +350,6 @@ mod tests {
let abschnitt = risdok.unwrap().nutzdaten.abschnitt;
assert_eq!(
abschnitt.ueberschriftPara.unwrap().content,
"Nichtigkeit eines wucherischen Vertrages."
);
let expected = vec![
AbsatzAbs {
gldsym: Some("§ 1.".into()),
@ -363,10 +374,6 @@ mod tests {
let abschnitt = risdok.unwrap().nutzdaten.abschnitt;
assert_eq!(
abschnitt.ueberschriftPara.unwrap().content,
"Rechtsfolgen der Nichtigkeit eines wucherischen Vertrages."
);
let expected = vec![
AbsatzAbs {
gldsym: Some("§ 7.".into()),