90 lines
No EOL
1.9 KiB
Markdown
90 lines
No EOL
1.9 KiB
Markdown
# libtbr
|
|
|
|
`libtbr` is swiss-knife toolbox for Taobin project.
|
|
|
|
```
|
|
cargo add --git https://gitlab.forthrd.io/Pakin/libtbr.git
|
|
```
|
|
|
|
```
|
|
cargo update
|
|
```
|
|
|
|
## Examples
|
|
|
|
### Initialize Config
|
|
|
|
```rust
|
|
use libtbr::recipe_functions::common;
|
|
|
|
// this read file `.tbcfg` in the current directory
|
|
let cfg = common::get_config();
|
|
|
|
let recipe_dir = cfg.get("RECIPE_DIR").unwrap();
|
|
```
|
|
|
|
---
|
|
|
|
### Get recipe from specific country (latest)
|
|
```rust
|
|
...
|
|
let latest_versions = grep_latest_versions(recipe_dir).unwrap();
|
|
|
|
// try get malaysia recipe, may fail if country does not exist
|
|
let mys_version = latest_versions.get("mys");
|
|
// try to create malaysia recipe model
|
|
let mys_recipe_model = common::create_recipe_model_from_file(common::create_recipe_path(
|
|
"mys",
|
|
*mys_version.unwrap(),
|
|
));
|
|
|
|
...
|
|
```
|
|
|
|
### Get list of material settings
|
|
|
|
```rust
|
|
// get current material settings including empty (0)
|
|
let mut used_in_mys = mys_recipe_model.list_material_settings();
|
|
used_in_mys.push("0".to_string());
|
|
```
|
|
|
|
### Get all recipe of expected material id
|
|
|
|
```rust
|
|
let aus_latest = common::create_recipe_model_from_file(common::create_recipe_path(
|
|
"aus",
|
|
*aus_version.unwrap(),
|
|
));
|
|
|
|
let prod_list = aus_latest.find_recipe_by_material_path_id("511214");
|
|
```
|
|
|
|
### Generate google sheet style table of recipe from file
|
|
|
|
```rust
|
|
// Experimental: expect current execution path to have `./test_result` folder first, and `config.RECIPE_DIR/{country}/{version_file_format}` must exist.
|
|
import::generate_recipe_sheet_table("mys", 626);
|
|
```
|
|
|
|
### Notes
|
|
|
|
|
|
Simple Snippet Patterns
|
|
|
|
```rust
|
|
// =============================================
|
|
// Get current material and convert to thai id
|
|
// =============================================
|
|
let curr_rpl_mat_id = rpl.materialPathId.as_i64().unwrap_or(0);
|
|
|
|
// strip off first 2
|
|
let pure_mat_id = if curr_rpl_mat_id > 300000 {
|
|
//
|
|
curr_rpl_mat_id.to_string()[2..]
|
|
.parse::<i64>()
|
|
.expect("not a number")
|
|
} else {
|
|
curr_rpl_mat_id
|
|
};
|
|
``` |