rename lawbuilder to builder to not have law twice in law::LawBuilder
All checks were successful
CI/CD Pipeline / test (push) Successful in 4m44s

This commit is contained in:
philipp 2024-02-27 08:52:53 +01:00
parent d25785984d
commit b8a6cccf0b
5 changed files with 21 additions and 21 deletions

View File

@ -14,10 +14,10 @@
// See the Licence for the specific language governing permissions and // See the Licence for the specific language governing permissions and
// limitations under the Licence. // limitations under the Licence.
use crate::law::ClassifierApplicable;
#[allow(clippy::wildcard_imports)] // I use *-operator on purpose: I want to receive a compiler #[allow(clippy::wildcard_imports)] // I use *-operator on purpose: I want to receive a compiler
// warning if I've not updated my `create_classifier` function // warning if I've not updated my `create_classifier` function
use crate::law::{self, responsible::*}; use crate::law::{self, responsible::*};
use crate::law::{ClassifierApplicable, LawBuilder};
use crate::misc::Error; use crate::misc::Error;
use crate::paragraph::Parser; use crate::paragraph::Parser;
use serde::Deserialize; use serde::Deserialize;
@ -92,11 +92,11 @@ impl Config {
/// ///
/// assert_eq!(law_id, 10001622); /// assert_eq!(law_id, 10001622);
/// ``` /// ```
pub fn load<P: AsRef<Path>>(path: P) -> Result<(usize, LawBuilder, Parser), Error> { pub fn load<P: AsRef<Path>>(path: P) -> Result<(usize, law::Builder, Parser), Error> {
let config_str = fs::read_to_string(path)?; let config_str = fs::read_to_string(path)?;
let config: Config = toml::from_str(&config_str)?; let config: Config = toml::from_str(&config_str)?;
let mut builder = LawBuilder::new(config.law.name); let mut builder = law::Builder::new(config.law.name);
for classifier in config.law.classifiers { for classifier in config.law.classifiers {
let to_add = law::Classifier::new( let to_add = law::Classifier::new(
&classifier.name, &classifier.name,

View File

@ -106,8 +106,8 @@ impl Law {
} }
} }
impl From<LawBuilder> for Law { impl From<Builder> for Law {
fn from(builder: LawBuilder) -> Self { fn from(builder: Builder) -> Self {
let mut ret = Vec::new(); let mut ret = Vec::new();
for header in builder.header { for header in builder.header {
@ -170,7 +170,7 @@ impl From<ClassifierInstance> for Vec<HeadingContent> {
/// Is used to generate a law struct. It's organized mainly by classifier. /// Is used to generate a law struct. It's organized mainly by classifier.
#[derive(Debug)] #[derive(Debug)]
pub struct LawBuilder { pub struct Builder {
name: String, name: String,
/// Structure of the law text /// Structure of the law text
@ -190,7 +190,7 @@ pub struct LawBuilder {
pub history: Vec<String>, pub history: Vec<String>,
} }
impl PartialEq for LawBuilder { impl PartialEq for Builder {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
self.classifiers == other.classifiers self.classifiers == other.classifiers
&& self.header == other.header && self.header == other.header
@ -198,13 +198,13 @@ impl PartialEq for LawBuilder {
} }
} }
impl Default for LawBuilder { impl Default for Builder {
fn default() -> Self { fn default() -> Self {
Self::new(String::new()) Self::new(String::new())
} }
} }
impl LawBuilder { impl Builder {
/// Creates a new law builder. Adds classifier for known law texts. /// Creates a new law builder. Adds classifier for known law texts.
pub fn new(name: String) -> Self { pub fn new(name: String) -> Self {
Self { Self {

View File

@ -28,7 +28,7 @@ use std::{
use log::info; use log::info;
use crate::{ use crate::{
law::LawBuilder, law,
misc::{fetch_with_retries, get_cache_dir, Error}, misc::{fetch_with_retries, get_cache_dir, Error},
}; };
@ -67,8 +67,8 @@ impl Parser {
self.replace.push((search.into(), replace.into())); self.replace.push((search.into(), replace.into()));
} }
/// Parses the content available in `url`. Calls appropriate functions in supplied `LawBuilder`. /// Parses the content available in `url`. Calls appropriate functions in supplied `Builder`.
pub fn parse(&self, url: &str, builder: &mut LawBuilder) -> Result<bool, Error> { pub fn parse(&self, url: &str, builder: &mut law::Builder) -> Result<bool, Error> {
info!("Parsing {url}"); info!("Parsing {url}");
let xml = fetch(url)?; let xml = fetch(url)?;
@ -77,7 +77,7 @@ impl Parser {
self.parse_from_str(&xml, builder) self.parse_from_str(&xml, builder)
} }
fn parse_from_str(&self, xml: &str, builder: &mut LawBuilder) -> Result<bool, Error> { fn parse_from_str(&self, xml: &str, builder: &mut law::Builder) -> Result<bool, Error> {
let mut xml = String::from(xml); let mut xml = String::from(xml);
for r in &self.remove { for r in &self.remove {
xml = xml.replace(r, ""); xml = xml.replace(r, "");

View File

@ -20,7 +20,7 @@ use std::iter::Peekable;
use log::{debug, trace}; use log::{debug, trace};
use roxmltree::{Children, Node}; use roxmltree::{Children, Node};
use crate::law::LawBuilder; use crate::law;
use crate::paragraph::parser::absatz::Absatz; use crate::paragraph::parser::absatz::Absatz;
use crate::paragraph::parser::{AbsatzAbs, Content, Fzinhalt, Kzinhalt, Ueberschrift}; use crate::paragraph::parser::{AbsatzAbs, Content, Fzinhalt, Kzinhalt, Ueberschrift};
@ -31,7 +31,7 @@ pub(crate) struct Abschnitt {
} }
impl Abschnitt { impl Abschnitt {
pub(crate) fn parse(n: Node, builder: &mut LawBuilder) -> Abschnitt { pub(crate) fn parse(n: Node, builder: &mut law::Builder) -> Abschnitt {
assert!(n.tag_name().name() == "abschnitt"); assert!(n.tag_name().name() == "abschnitt");
let mut ret = Abschnitt::default(); let mut ret = Abschnitt::default();
@ -97,7 +97,7 @@ impl Abschnitt {
// There are paragraph-specific meta-data at the top and bottom of each xml file. We parse // There are paragraph-specific meta-data at the top and bottom of each xml file. We parse
// those. When we encounter the title "Text" the real content starts, we stop parsing meta // those. When we encounter the title "Text" the real content starts, we stop parsing meta
// data. // data.
fn handle_metadata(&mut self, c: &mut Peekable<Children>, builder: &mut LawBuilder) { fn handle_metadata(&mut self, c: &mut Peekable<Children>, builder: &mut law::Builder) {
while c.peek().is_some() { while c.peek().is_some() {
let key = Ueberschrift::parse(c.next().unwrap(), "titel").content; let key = Ueberschrift::parse(c.next().unwrap(), "titel").content;
@ -146,7 +146,7 @@ impl Abschnitt {
// we have optionally headers. Such as "Einleitung", "Von den bürgerlichen Gesetzen üerhaupt," // we have optionally headers. Such as "Einleitung", "Von den bürgerlichen Gesetzen üerhaupt,"
// etc. If we have headers which indicate that we are done and we want to stop parsing // etc. If we have headers which indicate that we are done and we want to stop parsing
// ("anlage" + "Artikel" we indicate this wish by returning false. // ("anlage" + "Artikel" we indicate this wish by returning false.
fn handle_headers(c: &mut Peekable<Children>, builder: &mut LawBuilder) -> bool { fn handle_headers(c: &mut Peekable<Children>, builder: &mut law::Builder) -> bool {
while let Some(child) = c.peek() { while let Some(child) = c.peek() {
// Schiffahrtsgesetz: stop @ anlagen (for now) // Schiffahrtsgesetz: stop @ anlagen (for now)
if Ueberschrift::test(child, "anlage") { if Ueberschrift::test(child, "anlage") {

View File

@ -26,7 +26,7 @@ use log::trace;
use roxmltree::{Children, Node}; use roxmltree::{Children, Node};
use crate::{ use crate::{
law::{Content, LawBuilder}, law::{self, Content},
misc::Error, misc::Error,
paragraph::parser::absatz::Absatz, paragraph::parser::absatz::Absatz,
}; };
@ -57,7 +57,7 @@ impl<'a> Expect<'a> {
pub(crate) struct Risdok {} pub(crate) struct Risdok {}
impl Risdok { impl Risdok {
pub(crate) fn parse(n: Node, builder: &mut LawBuilder) -> bool { pub(crate) fn parse(n: Node, builder: &mut law::Builder) -> bool {
assert!(n.tag_name().name() == "risdok"); assert!(n.tag_name().name() == "risdok");
let mut c = n.children(); let mut c = n.children();
@ -74,7 +74,7 @@ impl Risdok {
true true
} }
pub(crate) fn from_str(xml: &str, builder: &mut LawBuilder) -> Result<bool, Error> { pub(crate) fn from_str(xml: &str, builder: &mut law::Builder) -> Result<bool, Error> {
let doc = roxmltree::Document::parse(xml)?; let doc = roxmltree::Document::parse(xml)?;
trace!("{doc:?}"); trace!("{doc:?}");
let root = doc.root(); let root = doc.root();
@ -98,7 +98,7 @@ impl Metadaten {
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub(crate) struct Nutzdaten {} pub(crate) struct Nutzdaten {}
impl Nutzdaten { impl Nutzdaten {
pub(crate) fn parse(n: Node, builder: &mut LawBuilder) -> bool { pub(crate) fn parse(n: Node, builder: &mut law::Builder) -> bool {
assert!(n.tag_name().name() == "nutzdaten"); assert!(n.tag_name().name() == "nutzdaten");
let mut c = n.children(); let mut c = n.children();