Skip to content

Commit

Permalink
fix file path
Browse files Browse the repository at this point in the history
  • Loading branch information
delihiros committed Nov 11, 2024
1 parent 04ffa44 commit 0d159d7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zengin"
version = "1.0.2"
version = "1.0.3"
edition = "2021"
description = "The Rust library for Zengin Code."
keywords = [ "zengin", "bank" ]
Expand All @@ -20,3 +20,7 @@ include_dir = "0.7.4"
regex = "1.11.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"


[lib]
doctest = false
17 changes: 4 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use include_dir::{include_dir, Dir};
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, env, error::Error, path::PathBuf};
use std::{collections::HashMap, error::Error};

static DATA_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/source-data/data");

Expand Down Expand Up @@ -28,12 +28,11 @@ impl Zengin {
/// let zengin = Zengin::new().unwrap();
/// ```
pub fn new() -> Result<Zengin, Box<dyn Error>> {
let bank_file = join_paths(&["banks.json"])?;
let mut banks = load_banks_from_file(bank_file.to_str().unwrap())?;
let mut banks = load_banks_from_file("banks.json")?;

for bank in banks.values_mut() {
let branch_file = join_paths(&["branches", &format!("{}.json", bank.code)])?;
let branches = load_branches_from_file(branch_file.to_str().unwrap())?;
let branches =
load_branches_from_file(format!("branches/{}.json", bank.code).as_str())?;
bank.branches = branches;
}

Expand Down Expand Up @@ -407,14 +406,6 @@ fn read_data_file(file_path: &str) -> std::result::Result<String, Box<dyn Error>
Ok(data_str.to_string())
}

fn join_paths(parts: &[&str]) -> Result<PathBuf, Box<dyn std::error::Error>> {
let mut path = env::current_dir()?;
for part in parts {
path.push(part);
}
Ok(path)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 0d159d7

Please sign in to comment.