Skip to content

Commit

Permalink
completed the sheba nodule to support custom processing for getting…
Browse files Browse the repository at this point in the history
… `account_number`.

added more test to sheba module.
started working on `Banking::extract_card_numbers`.
removed the `rustfmt.toml` for now.
  • Loading branch information
YouKnow-sys committed Nov 21, 2023
1 parent e6f46e0 commit 1e804a8
Show file tree
Hide file tree
Showing 7 changed files with 264 additions and 60 deletions.
2 changes: 0 additions & 2 deletions rustfmt.toml

This file was deleted.

5 changes: 5 additions & 0 deletions src/banking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ pub trait Banking: AsRef<str> {
sum % 10 == 0
}

/// Extract all the card numbers.
fn extract_card_numbers(&self) -> Vec<String> {
todo!()
}

/// Get the bank name from card number.
fn get_bank_name_from_card_number(&self) -> Option<&str> {
let number = self.as_ref();
Expand Down
63 changes: 60 additions & 3 deletions src/banking/sheba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ pub trait ShebaNumber: AsRef<str> {
self.iso_7064_mod_97_10().is_ok_and(|i| i == 1)
}

fn sheba_code_info(&self) -> Option<&ShebaInfo> {
fn get_sheba_info(&self) -> Option<ShebaInfo> {
if !self.is_valid_sheba_code() {
return None;
}
SHEBA_CODE_TABLE.get(&&self.as_ref()[4..7])

let digits = self.as_ref();
SHEBA_CODE_TABLE
.get(&&digits[4..7])
.map(|sc| sc.process(digits))
}

fn iso_7064_mod_97_10(&self) -> crate::Result<i32> {
Expand Down Expand Up @@ -45,6 +49,10 @@ impl_trait_for_string_types!(ShebaNumber);

#[cfg(test)]
mod sheba_code {
use crate::banking::sheba_table::{
process_parsian, process_pasargad, process_shahr, ShebaAccountNumber,
};

use super::*;

#[test]
Expand All @@ -57,6 +65,55 @@ mod sheba_code {

#[test]
fn sheba_code_info() {
assert!("IR210180000000009190404878".sheba_code_info().is_some())
assert!("IR210180000000009190404878".get_sheba_info().is_some());
assert!("IR012345678901234567890123".get_sheba_info().is_none());
assert!("IR012345678A01234567890123".get_sheba_info().is_none());

let sheba_info_pasargad = ShebaInfo {
code: "057",
nickname: "pasargad",
name: "Pasargad Bank",
persian_name: "بانک پاسارگاد",
account_number: Some(ShebaAccountNumber {
normal: "220800134473701".to_owned(),
formatted: "220-800-13447370-1".to_owned(),
}),
process: Some(process_pasargad),
};
let sheba_info_shahr = ShebaInfo {
code: "061",
nickname: "shahr",
name: "City Bank",
persian_name: "بانک شهر",
account_number: Some(ShebaAccountNumber {
normal: "700796858044".to_owned(),
formatted: "700796858044".to_owned(),
}),
process: Some(process_shahr),
};
let sheba_info_parsian = ShebaInfo {
code: "054",
nickname: "parsian",
name: "Parsian Bank",
persian_name: "بانک پارسیان",
account_number: Some(ShebaAccountNumber {
normal: "020817909002".to_owned(),
formatted: "002-00817909-002".to_owned(),
}),
process: Some(process_parsian),
};

assert_eq!(
"IR550570022080013447370101".get_sheba_info(),
Some(sheba_info_pasargad)
);
assert_eq!(
"IR790610000000700796858044".get_sheba_info(),
Some(sheba_info_shahr)
);
assert_eq!(
"IR820540102680020817909002".get_sheba_info(),
Some(sheba_info_parsian)
);
}
}
Loading

0 comments on commit 1e804a8

Please sign in to comment.