push2
This commit is contained in:
parent
93c43d3448
commit
ed109e1784
21
src/law.rs
21
src/law.rs
@ -23,6 +23,8 @@ pub(crate) struct LawBuilder {
|
||||
/// Structure of the law text
|
||||
classifiers: Vec<Classifier>,
|
||||
|
||||
last_header_index: Option<usize>,
|
||||
|
||||
/// Stores the header of the next paragraph
|
||||
next_para_header: Option<String>,
|
||||
}
|
||||
@ -47,6 +49,7 @@ impl LawBuilder {
|
||||
name: name.into(),
|
||||
classifiers,
|
||||
next_para_header: None,
|
||||
last_header_index: None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,6 +73,7 @@ impl LawBuilder {
|
||||
name: name.into(),
|
||||
classifiers,
|
||||
next_para_header: None,
|
||||
last_header_index: None,
|
||||
};
|
||||
|
||||
overview::parse(law_id.unwrap(), &mut builder);
|
||||
@ -80,10 +84,12 @@ impl LawBuilder {
|
||||
let classifier_index = self
|
||||
.classifiers
|
||||
.iter()
|
||||
.position(|class| class.contains(name));
|
||||
.position(|class| class.used_for(name));
|
||||
match classifier_index {
|
||||
Some(index) => {
|
||||
self.classifiers[index].add_instance(ClassifierInstance::new(name));
|
||||
let class = ClassifierInstance::new(name);
|
||||
self.classifiers[index].add_instance(class);
|
||||
self.last_header_index = Some(index);
|
||||
}
|
||||
None => panic!("No classifier for {name}"),
|
||||
}
|
||||
@ -91,8 +97,10 @@ impl LawBuilder {
|
||||
|
||||
/// Sets a new description for the last classifier.
|
||||
pub(crate) fn new_desc(&mut self, desc: &str) {
|
||||
if let Some(class) = self.classifiers.last_mut() {
|
||||
class.set_desc(desc);
|
||||
if let Some(index) = self.last_header_index {
|
||||
self.classifiers[index].set_desc(desc);
|
||||
} else {
|
||||
panic!("Not possible");
|
||||
}
|
||||
}
|
||||
|
||||
@ -197,6 +205,10 @@ impl Classifier {
|
||||
fn set_desc(&mut self, desc: &str) {
|
||||
self.instances.last_mut().unwrap().set_desc(desc);
|
||||
}
|
||||
|
||||
fn used_for(&self, name: &str) -> bool {
|
||||
name.contains(&self.name)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
@ -247,6 +259,7 @@ mod tests {
|
||||
},
|
||||
],
|
||||
next_para_header: None,
|
||||
last_header_index: Some(1),
|
||||
};
|
||||
assert_eq!(builder, expected);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user