patchwork_csv_utils 0.1.5-x86_64-darwin → 0.1.6-x86_64-darwin

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53bd775b8a062a5418959e170dce922799739ebbf4a4845eb48f65e889ae4fff
4
- data.tar.gz: 26e9f478dd57a8a9307b4536e242af967145c688ae9e4f4002655da86f8405cc
3
+ metadata.gz: dc9127c25a2fb4b4a0f99bd3730a4a82975fb249637f4c69ff31e0f5a68288de
4
+ data.tar.gz: 0b493f77942386540b3fc244fdfcdc853ce8dac8ae41df3fa37c06bff1777d50
5
5
  SHA512:
6
- metadata.gz: 256012cce7a6b5802c9ab05fe1e9063e7d99f63fa83f3f011f8375698a5abb1897312776c333fd9757e17c20b7674aff9b9997c3519effb39f9833be2be3f8e9
7
- data.tar.gz: 6ce45dcb2f95347350f6272fc8b0c4b84e0b8d24bd773d86b40e9b370de334839773c2363be1ef55e6809d6f510f19bfd25ebecdc669dd65dbb61a8aaa91b172
6
+ metadata.gz: 23a5632d5cfbaf9eca4397bff6199a34cd52c902a07640e490633260c94c122a8b5fc567c09ad3264e03eb31c5e5db2d676b1efe66ec322d7a6a3ddb4e7017f5
7
+ data.tar.gz: 656ca8052002ab45dadad145b141de4255ec72a36c9c4d975adfd1e9071e7ac3675647837492b0261e6385fc5159af3e02cf9af92aa1551fdd25efc05bd02589
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- patchwork_csv_utils (0.1.5)
4
+ patchwork_csv_utils (0.1.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -8,6 +8,6 @@ pub mod utils;
8
8
  fn init() -> Result<(), magnus::Error> {
9
9
  let module = define_module("CsvUtils")?;
10
10
  module.define_singleton_method("dedup", function!(dedup, 3))?;
11
- module.define_singleton_method("to_csv", function!(to_csv, 2))?;
11
+ module.define_singleton_method("to_csv", function!(to_csv, 3))?;
12
12
  Ok(())
13
13
  }
@@ -4,11 +4,17 @@ use std::io::{BufWriter, Write};
4
4
 
5
5
  use calamine::{Data, open_workbook, Range, Reader, Xls};
6
6
  use chrono::{NaiveDateTime, Utc};
7
- use magnus::Ruby;
7
+ use magnus::{RArray, Ruby};
8
8
 
9
9
  use crate::utils::{FileExtension, magnus_err};
10
10
 
11
- pub fn to_csv(ruby: &Ruby, xls_path: String, target_path: String) -> magnus::error::Result<()> {
11
+ pub fn to_csv(ruby: &Ruby, xls_path: String, target_path: String, exclusions: RArray) -> magnus::error::Result<()> {
12
+ let exclusions = RArray::to_vec(exclusions)?;
13
+
14
+ println!("xls_path: {:?}", xls_path);
15
+ println!("target_path: {:?}", target_path);
16
+ println!("exclusions: {:?}", exclusions);
17
+
12
18
  if !xls_path.has_extension(&["xls"]) {
13
19
  return Err(magnus::Error::new(ruby.exception_standard_error(), "xls_path must be an xls file".to_string()));
14
20
  }
@@ -23,14 +29,15 @@ pub fn to_csv(ruby: &Ruby, xls_path: String, target_path: String) -> magnus::err
23
29
  let csv_out_file = File::create(target_path.clone()).map_err(|e| magnus_err(ruby, e, format!("could not create csv file: {}", target_path).as_str()))?;
24
30
  let mut dest = BufWriter::new(csv_out_file);
25
31
 
26
- write_csv(ruby, &mut dest, &range, header_map)
32
+ write_csv(ruby, &mut dest, &range, header_map, exclusions)
27
33
  }
28
34
 
29
- fn write_csv<W: Write>(ruby: &Ruby, dest: &mut W, range: &Range<Data>, header_map: HashMap<String, usize>) -> magnus::error::Result<()> {
35
+ fn write_csv<W: Write>(ruby: &Ruby, dest: &mut W, range: &Range<Data>, header_map: HashMap<String, usize>, exclusions: Vec<String>) -> magnus::error::Result<()> {
30
36
  let n = range.get_size().1 - 1;
31
37
  for (ri, r) in range.rows().enumerate() {
32
38
  let mut date_value = Utc::now().naive_utc();
33
39
 
40
+ if skip_excluded_rows(&header_map, r, &exclusions) { continue; }
34
41
  if skip_empty_rows(r) { continue; }
35
42
  if skip_rows_with_no_request_id(&header_map, r) { continue; }
36
43
 
@@ -69,6 +76,16 @@ fn write_csv<W: Write>(ruby: &Ruby, dest: &mut W, range: &Range<Data>, header_ma
69
76
  Ok(())
70
77
  }
71
78
 
79
+ fn skip_excluded_rows(header_map: &HashMap<String, usize>, r: &[Data], exclusions: &Vec<String>) -> bool {
80
+ if let Some(request_id) = header_map.get("Request Id") {
81
+ let value = r[*request_id].to_string();
82
+ if exclusions.contains(&value) {
83
+ return true;
84
+ }
85
+ }
86
+ false
87
+ }
88
+
72
89
  fn skip_empty_rows(r: &[Data]) -> bool {
73
90
  if r.iter().all(|c| c == &Data::Empty) {
74
91
  return true;
Binary file
Binary file
Binary file
Binary file
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CsvUtils
4
- VERSION = '0.1.5'
4
+ VERSION = '0.1.6'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: patchwork_csv_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: x86_64-darwin
6
6
  authors:
7
7
  - kingsley.hendrickse
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-01 00:00:00.000000000 Z
11
+ date: 2024-08-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Deduplication of CSV files and XLS to CSV conversion.
14
14
  email: