output similar to how ris does it (for verification if everything has been properly parsed)
All checks were successful
CI/CD Pipeline / test (push) Successful in 1m7s
All checks were successful
CI/CD Pipeline / test (push) Successful in 1m7s
This commit is contained in:
@ -89,6 +89,25 @@ impl Law {
|
||||
Ok(builder.into())
|
||||
}
|
||||
|
||||
pub fn to_text(&self) {
|
||||
for header in &self.header {
|
||||
Self::print_text(header, 2);
|
||||
}
|
||||
}
|
||||
fn print_text(header: &Heading, level: usize) {
|
||||
println!("{}", header.to_text());
|
||||
for content in &header.content {
|
||||
match content {
|
||||
HeadingContent::Heading(h) => {
|
||||
Self::print_text(h, level + 1);
|
||||
}
|
||||
HeadingContent::Paragraph(p) => {
|
||||
println!("{}", p.to_text());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: add test
|
||||
pub fn to_md(&self) {
|
||||
for header in &self.header {
|
||||
@ -147,6 +166,18 @@ impl Display for Heading {
|
||||
}
|
||||
}
|
||||
|
||||
impl Heading {
|
||||
pub fn to_text(&self) -> String {
|
||||
let mut ret = format!("{}", self.name);
|
||||
|
||||
if let Some(desc) = &self.desc {
|
||||
ret.push_str(&format!("\n{desc}"));
|
||||
}
|
||||
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub enum HeadingContent {
|
||||
Paragraph(Section),
|
||||
@ -545,7 +576,7 @@ impl fmt::Debug for Section {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Section {
|
||||
impl Display for Section {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let mut to_write = if let Some(header) = &self.par_header {
|
||||
format!("{} ({})\n{}", self.symb, header, self.content)
|
||||
@ -560,6 +591,20 @@ impl fmt::Display for Section {
|
||||
}
|
||||
}
|
||||
|
||||
impl Section {
|
||||
pub fn to_text(&self) -> String {
|
||||
let mut ret = format!("{}\n", self.symb);
|
||||
|
||||
if let Some(par_header) = &self.par_header {
|
||||
ret.push_str(&format!("{}\n", par_header));
|
||||
}
|
||||
|
||||
ret.push_str(&format!("{}", self.content.to_text()));
|
||||
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
struct ClassifierInstance {
|
||||
name: String, //e.g. 1 Theilstück
|
||||
@ -721,6 +766,24 @@ impl Display for Content {
|
||||
}
|
||||
}
|
||||
|
||||
impl Content {
|
||||
pub fn to_text(&self) -> String {
|
||||
let mut ret = String::new();
|
||||
match self {
|
||||
Self::Text(a) => ret.push_str(&format!("{a}\n")),
|
||||
Self::List(a) | Self::Multi(a) => {
|
||||
let mut tmp = String::new();
|
||||
for aa in a {
|
||||
tmp.push_str(&format!("{}\n", aa.to_text()));
|
||||
}
|
||||
ret.push_str(&tmp);
|
||||
}
|
||||
}
|
||||
let ret = ret.trim();
|
||||
ret.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::fs;
|
||||
|
@ -40,6 +40,9 @@ struct Args {
|
||||
/// Clears the cache (downloaded laws + paragraphs)
|
||||
#[arg(long)]
|
||||
clear_cache: bool,
|
||||
|
||||
#[arg(long)]
|
||||
text: bool,
|
||||
}
|
||||
use tracing_subscriber::prelude::*;
|
||||
fn main() {
|
||||
@ -62,6 +65,9 @@ fn main() {
|
||||
parser.parse(par_url, &mut builder).unwrap();
|
||||
let law: Law = builder.into();
|
||||
println!("{law:?}");
|
||||
} else if args.text {
|
||||
let law = Law::from_config(&args.config).unwrap();
|
||||
law.to_text();
|
||||
} else {
|
||||
let law = Law::from_config(&args.config).unwrap();
|
||||
law.to_md();
|
||||
|
Reference in New Issue
Block a user