generated from OBJNULL/Dockerized-Rust
Compare commits
No commits in common. "8bfc7695a5ccf1b30be8fc1a3a3d9aa116cd91b0" and "92a666d9bcb62917983b763a265f912d40a89220" have entirely different histories.
8bfc7695a5
...
92a666d9bc
3 changed files with 16 additions and 57 deletions
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
// Structures
|
// Structures
|
||||||
pub struct Transaction {
|
pub struct Transaction {
|
||||||
pub description: String,
|
description: String,
|
||||||
pub date: String,
|
date: String,
|
||||||
pub amount: f64,
|
amount: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implementations
|
// Implementations
|
||||||
|
|
|
@ -18,6 +18,7 @@ fn main() -> Result<()> {
|
||||||
// Creating a File Reader & Reading
|
// Creating a File Reader & Reading
|
||||||
let reader = Reader::new(&args.file_input.clone())?;
|
let reader = Reader::new(&args.file_input.clone())?;
|
||||||
let text = reader.extract();
|
let text = reader.extract();
|
||||||
|
println!("Text Content: {}", text.clone());
|
||||||
|
|
||||||
// Creating a Parser to read the Text Content
|
// Creating a Parser to read the Text Content
|
||||||
let mut parser = Parser::new(text);
|
let mut parser = Parser::new(text);
|
||||||
|
|
|
@ -32,27 +32,6 @@ impl Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
fn pre_check(&mut self, line: &str) -> bool {
|
|
||||||
// Should be pause?
|
|
||||||
if line.contains("continued") {
|
|
||||||
self.paused = true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// End of Section?
|
|
||||||
if line.contains("Total") {
|
|
||||||
self.mode = ParserModes::None;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checking if it starts with a number
|
|
||||||
if !line.chars().next().map_or(false, |c| c.is_ascii_digit()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
fn none(&mut self, line: &str) {
|
fn none(&mut self, line: &str) {
|
||||||
// Checking if the line is the beginning of a table
|
// Checking if the line is the beginning of a table
|
||||||
if line == "Other withdrawals, debits and service charges" {
|
if line == "Other withdrawals, debits and service charges" {
|
||||||
|
@ -61,38 +40,22 @@ impl Parser {
|
||||||
self.mode = ParserModes::Credit;
|
self.mode = ParserModes::Credit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn transaction(&mut self, t_type: ParserModes, line: &str) {
|
fn debit(&mut self, line: &str) {
|
||||||
// Perform a Pre-Check
|
// Should be pause?
|
||||||
if !self.pre_check(line) {
|
if line.contains("continued") {
|
||||||
|
self.paused = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Splitting by Parts
|
// Checking if it starts with a number
|
||||||
let parts: Vec<&str> = line.split_whitespace().collect();
|
if !line.chars().next().map_or(false, |c| c.is_ascii_digit()) {
|
||||||
|
return;
|
||||||
// Collecting based on Parts
|
|
||||||
let description = parts[2..parts.len() - 1].join(" ");
|
|
||||||
let mut amount: f64 = parts.last().unwrap().parse().unwrap_or(0.0);
|
|
||||||
let date = parts[0].to_owned();
|
|
||||||
|
|
||||||
// Is it a debit?
|
|
||||||
match t_type {
|
|
||||||
ParserModes::Debit => {
|
|
||||||
amount = -amount;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creating a new Transaction
|
// Print the line
|
||||||
let new_transaction = Transaction {
|
println!("Debit: {}", line);
|
||||||
description,
|
|
||||||
amount,
|
|
||||||
date,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Adding the transaction to our list
|
|
||||||
self.transactions.push(new_transaction);
|
|
||||||
}
|
}
|
||||||
|
fn credit(&mut self, line: &str) {}
|
||||||
|
|
||||||
fn pause_check(&mut self, line: &str) {
|
fn pause_check(&mut self, line: &str) {
|
||||||
// Check to see if the line contains "continued"
|
// Check to see if the line contains "continued"
|
||||||
|
@ -124,14 +87,9 @@ impl Parser {
|
||||||
// Switching based on Mode
|
// Switching based on Mode
|
||||||
match self.mode {
|
match self.mode {
|
||||||
ParserModes::None => self.none(line),
|
ParserModes::None => self.none(line),
|
||||||
ParserModes::Debit => self.transaction(ParserModes::Credit, line),
|
ParserModes::Debit => self.debit(line),
|
||||||
ParserModes::Credit => self.transaction(ParserModes::Credit, line),
|
ParserModes::Credit => self.credit(line),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DEBUG: Print all transactions
|
|
||||||
for t in &self.transactions {
|
|
||||||
println!("Transaction {}: {} on {}", t.description, t.amount, t.date);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue