use regex::Regex;
#[derive(Clone)]
pub struct Options {
pub max_elems_to_parse: usize,
pub nb_top_candidates: usize,
pub char_threshold: usize,
pub classes_to_preserve: Vec<String>,
pub keep_classes: bool,
pub disable_json_ld: bool,
pub allowed_video_regex: Option<Regex>,
pub link_density_modifier: f64,
pub debug: bool,
}
impl Default for Options {
fn default() -> Self {
Self {
max_elems_to_parse: 0,
nb_top_candidates: 5,
char_threshold: 500,
classes_to_preserve: vec!["page".to_string()],
keep_classes: false,
disable_json_ld: false,
allowed_video_regex: None,
link_density_modifier: 0.0,
debug: false,
}
}
}
impl Options {
pub fn new() -> Self {
Self::default()
}
pub fn max_elems_to_parse(mut self, max: usize) -> Self {
self.max_elems_to_parse = max;
self
}
pub fn nb_top_candidates(mut self, n: usize) -> Self {
self.nb_top_candidates = n;
self
}
pub fn char_threshold(mut self, threshold: usize) -> Self {
self.char_threshold = threshold;
self
}
pub fn classes_to_preserve(mut self, classes: Vec<String>) -> Self {
self.classes_to_preserve.extend(classes);
self
}
pub fn keep_classes(mut self, keep: bool) -> Self {
self.keep_classes = keep;
self
}
pub fn disable_json_ld(mut self, disable: bool) -> Self {
self.disable_json_ld = disable;
self
}
pub fn allowed_video_regex(mut self, regex: Regex) -> Self {
self.allowed_video_regex = Some(regex);
self
}
pub fn link_density_modifier(mut self, modifier: f64) -> Self {
self.link_density_modifier = modifier;
self
}
pub fn debug(mut self, debug: bool) -> Self {
self.debug = debug;
self
}
}
#[derive(Clone)]
pub struct ReaderableOptions {
pub min_score: f64,
pub min_content_length: usize,
}
impl Default for ReaderableOptions {
fn default() -> Self {
Self {
min_score: 20.0,
min_content_length: 140,
}
}
}
impl ReaderableOptions {
pub fn new() -> Self {
Self::default()
}
pub fn min_score(mut self, score: f64) -> Self {
self.min_score = score;
self
}
pub fn min_content_length(mut self, length: usize) -> Self {
self.min_content_length = length;
self
}
}