Skip to content

Commit

Permalink
feat: divi: Support WealthyExile csv input
Browse files Browse the repository at this point in the history
  • Loading branch information
shonya3 committed Aug 28, 2024
1 parent 92d9d7a commit 3bff166
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion divi/src/card_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
pub struct CardRecord {
#[serde(alias = "Name")]
pub name: String,
#[serde(alias = "stackSize")]
#[serde(alias = "Quantity")]
pub amount: u32,
#[serde(alias = "calculated")]
pub price: Option<f32>,
Expand Down
9 changes: 6 additions & 3 deletions divi/src/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,10 @@ impl Display for MissingHeadersError {
/// Parsing helper. Uses for CSV data
fn remove_lines_before_headers(s: &str) -> Result<String, MissingHeadersError> {
match s.lines().enumerate().find(|(_index, line)| {
line.contains("name")
&& ["amount", "stackSize"]
["Name", "name"]
.iter()
.any(|variant| line.contains(variant))
&& ["amount", "stackSize", "Quantity"]
.iter()
.any(|variant| line.contains(variant))
}) {
Expand Down Expand Up @@ -320,8 +322,9 @@ fn preserve_column_order(columns: &[Column]) -> Vec<Column> {

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NameAmount {
#[serde(alias = "Name")]
pub name: String,
#[serde(alias = "stackSize")]
#[serde(alias = "stackSize", alias = "Quantity")]
pub amount: u32,
}

Expand Down

0 comments on commit 3bff166

Please sign in to comment.