push
This commit is contained in:
parent
11d55ed379
commit
5a238f6521
10
src/law.rs
10
src/law.rs
@ -19,6 +19,7 @@ pub(crate) struct LawBuilder {
|
|||||||
name: String, //ABGB, UrhG
|
name: String, //ABGB, UrhG
|
||||||
classifiers: Vec<Classifier>,
|
classifiers: Vec<Classifier>,
|
||||||
cur_classifier_index: Option<usize>,
|
cur_classifier_index: Option<usize>,
|
||||||
|
next_para_header: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LawBuilder {
|
impl LawBuilder {
|
||||||
@ -37,6 +38,7 @@ impl LawBuilder {
|
|||||||
name: name.into(),
|
name: name.into(),
|
||||||
classifiers,
|
classifiers,
|
||||||
cur_classifier_index: None,
|
cur_classifier_index: None,
|
||||||
|
next_para_header: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,6 +61,7 @@ impl LawBuilder {
|
|||||||
name: name.into(),
|
name: name.into(),
|
||||||
classifiers,
|
classifiers,
|
||||||
cur_classifier_index: None,
|
cur_classifier_index: None,
|
||||||
|
next_para_header: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
overview::parse(law_id.unwrap(), &mut builder);
|
overview::parse(law_id.unwrap(), &mut builder);
|
||||||
@ -91,6 +94,10 @@ impl LawBuilder {
|
|||||||
panic!("Expected at least one classifier");
|
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 {
|
pub(crate) struct Section {
|
||||||
@ -184,7 +191,7 @@ impl Classifier {
|
|||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub(crate) enum Content {
|
pub(crate) enum Content {
|
||||||
Text(String), //This is my direct law text
|
Text(String), //This is my direct law text
|
||||||
Item((String, Box<Content>)), //(1) This is general law. (2) This is more specific law
|
Item(Vec<Box<Content>>), //(1) This is general law. (2) This is more specific law
|
||||||
List(Vec<Box<Content>>), //1. my first item
|
List(Vec<Box<Content>>), //1. my first item
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,6 +235,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
cur_classifier_index: Some(1),
|
cur_classifier_index: Some(1),
|
||||||
|
next_para_header: Some("2. Abschnitt".into()),
|
||||||
};
|
};
|
||||||
assert_eq!(builder, expected);
|
assert_eq!(builder, expected);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,10 @@ use std::fmt::Display;
|
|||||||
|
|
||||||
use roxmltree::Node;
|
use roxmltree::Node;
|
||||||
|
|
||||||
use crate::{law::LawBuilder, Error};
|
use crate::{
|
||||||
|
law::{Content, LawBuilder},
|
||||||
|
Error,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub(crate) struct Risdok {
|
pub(crate) struct Risdok {
|
||||||
@ -38,9 +41,6 @@ impl Risdok {
|
|||||||
|
|
||||||
impl Display for Risdok {
|
impl Display for Risdok {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
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 {
|
for abs in &self.nutzdaten.abschnitt.absatze {
|
||||||
let mut w = String::new();
|
let mut w = String::new();
|
||||||
if let Some(symb) = &abs.gldsym {
|
if let Some(symb) = &abs.gldsym {
|
||||||
@ -86,7 +86,6 @@ impl Nutzdaten {
|
|||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub(crate) struct Abschnitt {
|
pub(crate) struct Abschnitt {
|
||||||
ueberschriftPara: Option<Ueberschrift>,
|
|
||||||
absatze: Vec<AbsatzAbs>,
|
absatze: Vec<AbsatzAbs>,
|
||||||
}
|
}
|
||||||
impl Abschnitt {
|
impl Abschnitt {
|
||||||
@ -138,10 +137,10 @@ impl Abschnitt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut ueberschriftPara = None;
|
|
||||||
if let Some(child) = c.peek() {
|
if let Some(child) = c.peek() {
|
||||||
if Ueberschrift::test(child, "para") {
|
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
|
// Skip all UeberschriftTitle and Absatz
|
||||||
loop {
|
loop {
|
||||||
match c.peek() {
|
match c.peek() {
|
||||||
@ -179,10 +197,7 @@ impl Abschnitt {
|
|||||||
|
|
||||||
assert_eq!(c.next(), None);
|
assert_eq!(c.next(), None);
|
||||||
|
|
||||||
Self {
|
Self { absatze }
|
||||||
ueberschriftPara,
|
|
||||||
absatze,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,10 +350,6 @@ mod tests {
|
|||||||
|
|
||||||
let abschnitt = risdok.unwrap().nutzdaten.abschnitt;
|
let abschnitt = risdok.unwrap().nutzdaten.abschnitt;
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
abschnitt.ueberschriftPara.unwrap().content,
|
|
||||||
"Nichtigkeit eines wucherischen Vertrages."
|
|
||||||
);
|
|
||||||
let expected = vec![
|
let expected = vec![
|
||||||
AbsatzAbs {
|
AbsatzAbs {
|
||||||
gldsym: Some("§ 1.".into()),
|
gldsym: Some("§ 1.".into()),
|
||||||
@ -363,10 +374,6 @@ mod tests {
|
|||||||
|
|
||||||
let abschnitt = risdok.unwrap().nutzdaten.abschnitt;
|
let abschnitt = risdok.unwrap().nutzdaten.abschnitt;
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
abschnitt.ueberschriftPara.unwrap().content,
|
|
||||||
"Rechtsfolgen der Nichtigkeit eines wucherischen Vertrages."
|
|
||||||
);
|
|
||||||
let expected = vec![
|
let expected = vec![
|
||||||
AbsatzAbs {
|
AbsatzAbs {
|
||||||
gldsym: Some("§ 7.".into()),
|
gldsym: Some("§ 7.".into()),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user