Rename parser

This commit is contained in:
Rémi BERTHO 2020-05-24 09:27:45 +02:00
parent 38afb86753
commit bddd41dde8
Signed by: dalan
GPG key ID: EE3B917931C07B64
4 changed files with 9 additions and 7 deletions

View file

@ -8,16 +8,16 @@ use crate::price_result::PriceResult;
use arraygen::Arraygen;
use url::Url;
pub trait Parser{
pub trait PriceParser{
fn new() -> Self where Self :Sized;
fn can_parse(&self, url : &Url) -> bool;
fn parse(&self, html : &Html) -> PriceResult;
}
#[derive(Arraygen, Debug)]
#[gen_array(pub fn get: & dyn Parser)]
#[gen_array(pub fn get_price: & dyn PriceParser)]
pub struct List {
#[in_array(get)]
#[in_array(get_price)]
darty: darty::Darty
}

View file

@ -1,4 +1,4 @@
use super::Parser;
use super::PriceParser;
use crate::PriceResult;
use scraper::{Selector, Html};
use url::Url;
@ -10,7 +10,7 @@ pub struct Darty {
product_selector: Selector
}
impl Parser for Darty {
impl PriceParser for Darty {
fn new() -> Self {
Darty {
price_selector: Selector::parse(r#".darty_prix"#).unwrap(),

View file

@ -27,7 +27,7 @@ impl PriceChecker {
let response = self.client.get(url.clone()).send().unwrap();
let text = response.text().unwrap();
let document = Html::parse_document(&text);
let parser = *self.parser_list.get().iter().find(|p| p.can_parse(&url)).unwrap();
let parser = *self.parser_list.get_price().iter().find(|p| p.can_parse(&url)).unwrap();
parser.parse(&document)
}
}