patchwork_csv_utils 0.1.5-arm64-darwin → 0.1.6-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ccdea0ba6abfc936797f007183000983de9b15b9c195dfcdcfcd6ed3e63b5119
4
- data.tar.gz: af20ff750dbbf82f86a3aaad20242770e1327db98218dd5e93381f3627f744bb
3
+ metadata.gz: 29f014ebb0d7fe82e824325e564767deb1cfed92e24c1f487171457214316ac2
4
+ data.tar.gz: 608a2edb81ccedebc584762b5c30a2eb24e2c002fae1d28190cf7cf307cc23b3
5
5
  SHA512:
6
- metadata.gz: d134cfdfafab51d74fef17480c0aad78c1033d0fc3ae443cd57ad5ce838a76fdf44a05970c295177eb6b9b26f556c2d37a8a2b04f05d67fec194f22991da8628
7
- data.tar.gz: dc188247d6c270c0640f3f3b88173b4e3ff97d23c4b077749219fcf33c0394616b1b95b3d22e9fd5126fb2741f72bea316c1d0f09a7798484e775663661c0daa
6
+ metadata.gz: de08a499be3bd3106978ba9b56b81afd3b1bfb634262405aefae74cab36543390d9f825e2bcdf2d25601bbdcea2fec3f4853bff470a39a89a484846477b2dd59
7
+ data.tar.gz: 6b25c5917e837b3de71570f0d12c14d92cf3ef588d36ca660611fbae4a6ca17cc2c04af641304f7dc755cb69ea57b5a38c324ca09b9322af62dd8d0900659718
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: arm64-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: