fix ci
This commit is contained in:
55
src/law.rs
55
src/law.rs
@ -1,24 +1,29 @@
|
||||
use crate::overview;
|
||||
|
||||
pub(crate) struct Law {
|
||||
name: String, //ABGB, UrhG
|
||||
section: Vec<Section>, // § 1, § 2, ...
|
||||
}
|
||||
// pub(crate) struct Law {
|
||||
// name: String, //ABGB, UrhG
|
||||
// section: Vec<Section>, // § 1, § 2, ...
|
||||
// }
|
||||
|
||||
impl Law {
|
||||
pub(crate) fn new(name: &str) -> Self {
|
||||
Self {
|
||||
name: name.into(),
|
||||
section: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
// impl Law {
|
||||
// pub(crate) fn new(name: &str) -> Self {
|
||||
// Self {
|
||||
// name: name.into(),
|
||||
// section: Vec::new(),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
/// Is used to generate a law struct. It's organized mainly by classifier.
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub(crate) struct LawBuilder {
|
||||
/// Name of the law
|
||||
name: String, //ABGB, UrhG
|
||||
|
||||
/// Structure of the law text
|
||||
classifiers: Vec<Classifier>,
|
||||
cur_classifier_index: Option<usize>,
|
||||
|
||||
/// Stores the header of the next paragraph
|
||||
next_para_header: Option<String>,
|
||||
}
|
||||
|
||||
@ -33,15 +38,19 @@ impl LawBuilder {
|
||||
let mut abschnitt = Classifier::new("Abschnitt");
|
||||
abschnitt.set_parent(hauptstueck);
|
||||
classifiers.push(abschnitt);
|
||||
} else if name == "no-headers" {
|
||||
let mut class = Classifier::new("");
|
||||
class.add_instance(ClassifierInstance::new(""));
|
||||
classifiers.push(class);
|
||||
}
|
||||
Self {
|
||||
name: name.into(),
|
||||
classifiers,
|
||||
cur_classifier_index: None,
|
||||
next_para_header: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new law builder. Adds classifier for known law texts.
|
||||
pub(crate) fn new(name: &str) {
|
||||
//TODO: return Law (not LawBuilder)
|
||||
let mut classifiers = Vec::new();
|
||||
@ -60,13 +69,13 @@ impl LawBuilder {
|
||||
let mut builder = Self {
|
||||
name: name.into(),
|
||||
classifiers,
|
||||
cur_classifier_index: None,
|
||||
next_para_header: None,
|
||||
};
|
||||
|
||||
overview::parse(law_id.unwrap(), &mut builder);
|
||||
}
|
||||
|
||||
/// Sets a new header.
|
||||
pub(crate) fn new_header(&mut self, name: &str) {
|
||||
let classifier_index = self
|
||||
.classifiers
|
||||
@ -75,26 +84,28 @@ impl LawBuilder {
|
||||
match classifier_index {
|
||||
Some(index) => {
|
||||
self.classifiers[index].add_instance(ClassifierInstance::new(name));
|
||||
self.cur_classifier_index = Some(index);
|
||||
}
|
||||
None => panic!("No classifier for {name}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets a new description for the last classifier.
|
||||
pub(crate) fn new_desc(&mut self, desc: &str) {
|
||||
if let Some(index) = self.cur_classifier_index {
|
||||
self.classifiers[index].set_desc(desc);
|
||||
if let Some(class) = self.classifiers.last_mut() {
|
||||
class.set_desc(desc);
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds a new paragraph.
|
||||
pub(crate) fn new_par(&mut self, par: Content) {
|
||||
if let Some(index) = self.cur_classifier_index {
|
||||
self.classifiers[index].add_par(par);
|
||||
if let Some(class) = self.classifiers.last_mut() {
|
||||
class.add_par(par);
|
||||
} else {
|
||||
panic!("Expected at least one classifier");
|
||||
}
|
||||
}
|
||||
|
||||
/// Next paragraph has a header, store its name.
|
||||
pub(crate) fn new_next_para_header(&mut self, header: &str) {
|
||||
self.next_para_header = Some(header.into());
|
||||
}
|
||||
@ -198,6 +209,7 @@ pub(crate) enum Content {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
@ -234,8 +246,7 @@ mod tests {
|
||||
}],
|
||||
},
|
||||
],
|
||||
cur_classifier_index: Some(1),
|
||||
next_para_header: Some("2. Abschnitt".into()),
|
||||
next_para_header: None,
|
||||
};
|
||||
assert_eq!(builder, expected);
|
||||
}
|
||||
|
@ -331,8 +331,6 @@ impl Layoutdaten {
|
||||
mod tests {
|
||||
use std::{fs::File, io::Read};
|
||||
|
||||
use crate::law::Law;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
@ -341,7 +339,7 @@ mod tests {
|
||||
let mut xml = String::new();
|
||||
file.read_to_string(&mut xml).unwrap();
|
||||
|
||||
let mut builder = LawBuilder::test("a");
|
||||
let mut builder = LawBuilder::test("no-headers");
|
||||
let risdok = Risdok::from_str(&xml, &mut builder);
|
||||
if risdok.is_err() {
|
||||
println!("{:#?}", risdok.as_ref().err());
|
||||
@ -364,7 +362,7 @@ mod tests {
|
||||
let mut file = File::open("data/par/wucher7.xml").unwrap();
|
||||
let mut xml = String::new();
|
||||
file.read_to_string(&mut xml).unwrap();
|
||||
let mut builder = LawBuilder::test("a");
|
||||
let mut builder = LawBuilder::test("no-headers");
|
||||
|
||||
let risdok = Risdok::from_str(&xml, &mut builder);
|
||||
if risdok.is_err() {
|
||||
|
Reference in New Issue
Block a user