Add parser list macro
This commit is contained in:
parent
cec9900b45
commit
e37425de5d
2 changed files with 34 additions and 27 deletions
2
TODO.md
2
TODO.md
|
@ -1,7 +1,7 @@
|
|||
# TODO
|
||||
|
||||
* [x] Récupération prix darty avec [scraper](https://crates.io/crates/scraper) et [reqwest](https://crates.io/crates/reqwest)
|
||||
* [ ] Ajout du support de la Fnac, …
|
||||
* [x] Ajout du support de la Fnac, …
|
||||
* [x] Récupération URL ligne de commande avec [clap](https://crates.io/crates/clap)
|
||||
* [ ] Ajout de SearchParser pour recherché un article sur tous les parseurs
|
||||
* [ ] Ajout des pays avec [celes](https://crates.io/crates/celes) : recherche uniquement sur les parser du pays et parseur multi pays (amazon)
|
||||
|
|
|
@ -27,34 +27,41 @@ pub trait PriceParser : Parser{
|
|||
|
||||
// @todo Macro générateur liste et tests
|
||||
|
||||
#[derive(Arraygen, Debug)]
|
||||
#[gen_array(pub fn get_price: & dyn PriceParser)]
|
||||
/// Represent the list of all the parser
|
||||
pub struct List {
|
||||
#[in_array(get_price)]
|
||||
darty: darty::Darty,
|
||||
#[in_array(get_price)]
|
||||
fnac: fnac::Fnac,
|
||||
#[in_array(get_price)]
|
||||
du_bruit_dans_la_cuisine: du_bruit_dans_la_cuisine::DuBruitDansLaCuisine,
|
||||
#[in_array(get_price)]
|
||||
ldlc: ldlc::LDLC,
|
||||
#[in_array(get_price)]
|
||||
amazon: amazon::Amazon,
|
||||
macro_rules! gen_list {
|
||||
( $([$module:ident::$name:ident : $($array:ident),*]),* ) => {
|
||||
#[derive(Arraygen, Debug)]
|
||||
#[gen_array(pub fn get_price: & dyn PriceParser)]
|
||||
pub struct List {
|
||||
$(
|
||||
$(
|
||||
#[in_array($array)]
|
||||
)*
|
||||
$module: $module::$name
|
||||
),*
|
||||
}
|
||||
|
||||
|
||||
impl List {
|
||||
/// Create the list
|
||||
pub fn new() -> Result<Self> {
|
||||
Ok(List {
|
||||
$(
|
||||
$module: $module::$name::new()?
|
||||
),*
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
impl List {
|
||||
/// Create the list
|
||||
pub fn new() -> Result<Self> {
|
||||
Ok(List {
|
||||
darty: darty::Darty::new()?,
|
||||
fnac: fnac::Fnac::new()?,
|
||||
du_bruit_dans_la_cuisine: du_bruit_dans_la_cuisine::DuBruitDansLaCuisine::new()?,
|
||||
ldlc: ldlc::LDLC::new()?,
|
||||
amazon: amazon::Amazon::new()?
|
||||
})
|
||||
}
|
||||
}
|
||||
gen_list!(
|
||||
[darty::Darty : get_price],
|
||||
[fnac::Fnac : get_price],
|
||||
[du_bruit_dans_la_cuisine::DuBruitDansLaCuisine : get_price],
|
||||
[ldlc::LDLC : get_price],
|
||||
[amazon::Amazon : get_price]
|
||||
);
|
||||
|
||||
#[test]
|
||||
fn test_parser_list() {
|
||||
|
|
Loading…
Reference in a new issue