-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from josueBarretogit/get-data-crates-from-json
Get data crates from json
- Loading branch information
Showing
10 changed files
with
275 additions
and
1,547 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,69 @@ | ||
use crate::backend::{Categories, CategoriesWithSubCategories, Crates, Table, TableEntry}; | ||
use crate::scraper::scraper::Group; | ||
|
||
pub mod content_parser; | ||
|
||
#[cfg(test)] | ||
pub trait ContentParser { | ||
fn get_general_crates(&self) -> Table; | ||
|
||
fn get_crates(&self, category: &Categories) -> Table; | ||
|
||
fn get_crates_with_sub(&self, category: &CategoriesWithSubCategories) -> Table; | ||
} | ||
|
||
impl From<&Group> for Table { | ||
fn from(value: &Group) -> Self { | ||
let mut entries: Vec<TableEntry> = Vec::new(); | ||
|
||
//This means this is parsing a category with 1 table | ||
if let Some(purposes) = &value.purposes { | ||
for purpose in purposes { | ||
let mut crates: Vec<Crates> = Vec::new(); | ||
|
||
for recommendation in &purpose.recommendations { | ||
crates.push(Crates { | ||
name: recommendation.name.clone(), | ||
description: recommendation | ||
.notes | ||
.clone() | ||
.unwrap_or("No description".to_string()), | ||
features: None, | ||
}); | ||
} | ||
|
||
entries.push(TableEntry { | ||
use_case: String::default(), | ||
crates, | ||
}); | ||
} | ||
|
||
mod test { | ||
use crate::{ | ||
backend::{Crates, Table, TableEntry}, | ||
content_parser::content_parser::ContentParser, | ||
}; | ||
return Table { entries }; | ||
}; | ||
|
||
#[test] | ||
fn general_table_has_expected_data() { | ||
//I dont know how to test this xd | ||
todo!() | ||
//Parsing a category with multiple tables | ||
if let Some(subgroups) = &value.subgroups { | ||
for subgroup in subgroups { | ||
let mut crates: Vec<Crates> = Vec::new(); | ||
if let Some(purposes) = &subgroup.purposes { | ||
for purpose in purposes { | ||
purpose.recommendations.iter().for_each(|recommendation| { | ||
crates.push(Crates { | ||
name: recommendation.name.clone(), | ||
description: recommendation | ||
.notes | ||
.clone() | ||
.unwrap_or("No description".to_string()), | ||
features: None, | ||
}); | ||
}); | ||
} | ||
} | ||
entries.push(TableEntry { | ||
use_case: String::default(), | ||
crates, | ||
}); | ||
} | ||
}; | ||
Table { entries } | ||
} | ||
} |
Oops, something went wrong.