diff options
Diffstat (limited to 'src/record.rs')
-rw-r--r-- | src/record.rs | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/record.rs b/src/record.rs new file mode 100644 index 0000000..841855e --- /dev/null +++ b/src/record.rs @@ -0,0 +1,72 @@ +#[derive(Debug)] +pub struct Record { + account: String, + currency: String, + record_type: String, + main_type: String, + subcategory: String, + price: f64, + fee: f64, + bonus: f64, + name: String, + store: Option<String>, + date: Date, + time: Option<String>, + project: Option<String>, + note: Option<String>, + tags: Option<String>, + target: Option<String>, +} + +#[derive(Debug)] +struct Date { + month: i32, + day: i32, + year: i32, +} + +impl Record { + pub fn new(r: csv::StringRecord) -> Self { + Record { + account: r[0].to_string(), + currency: r[1].to_string(), + record_type: r[2].to_string(), + main_type: r[3].to_string(), + subcategory: r[4].to_string(), + price: r[5].parse().unwrap(), + fee: r[6].parse().unwrap(), + bonus: r[7].parse().unwrap(), + name: r[8].to_string(), + store: r.get(9).map(|s| s.to_string()), + date: { + let d = r[10].split('/').collect::<Vec<&str>>(); + Date { + month: d[0].parse().unwrap(), + day: d[1].parse().unwrap(), + year: d[2].parse().unwrap(), + } + }, + time: r.get(11).map(|s| s.to_string()), + project: r.get(12).map(|s| s.to_string()), + note: r.get(13).map(|s| s.to_string()), + tags: r.get(14).map(|s| s.to_string()), + target: r.get(15).map(|s| s.to_string()), + } + } + + pub fn cal(&self) -> f64 { + self.price + self.fee + self.bonus + } + + pub fn record_type(&self) -> &str { + self.record_type.as_str() + } + + pub fn project(&self) -> Option<String> { + self.project.clone() + } + + pub fn currency(&self) -> String { + self.currency.clone() + } +} |