Rename parser
This commit is contained in:
parent
38afb86753
commit
bddd41dde8
4 changed files with 9 additions and 7 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue