patchwork_csv_utils 0.1.19-x86_64-linux → 0.1.21-x86_64-linux
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 +4 -4
 - data/Gemfile.lock +1 -1
 - data/ext/csv_utils/src/lib.rs +2 -2
 - data/ext/csv_utils/src/utils/csv.rs +11 -7
 - data/ext/csv_utils/src/utils/xls.rs +11 -5
 - data/lib/csv_utils/2.7/csv_utils.so +0 -0
 - data/lib/csv_utils/3.0/csv_utils.so +0 -0
 - data/lib/csv_utils/3.1/csv_utils.so +0 -0
 - data/lib/csv_utils/3.2/csv_utils.so +0 -0
 - data/lib/csv_utils/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: '05919ff686082e5b6623d95609a88ce8becf427d84ac5fd5b75f25fb805a886a'
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 18a5291b26af0ab431f1ff0bcd7954459292caaaefee3c7c2eb71de89921aa5a
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: c2efa877128736c0a0e889a69b043f0736659ccb1adb7b37c883c05d636d8edeed74419437cc32e10c8ff625520d32f8c795a356bce93f61234b3885ca9011f9
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 4562c3b6c7f4ed1abecc39e88465bcdff1a5689a4995ce6b42dac8623c07d7fa47736936e2f7df818281b8800e4764b40a93f6c53a7c57e607a92cdae08476d0
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/ext/csv_utils/src/lib.rs
    CHANGED
    
    | 
         @@ -9,7 +9,7 @@ pub mod utils; 
     | 
|
| 
       9 
9 
     | 
    
         
             
            fn init() -> Result<(), magnus::Error> {
         
     | 
| 
       10 
10 
     | 
    
         
             
                let module = define_module("CsvUtils")?;
         
     | 
| 
       11 
11 
     | 
    
         
             
                module.define_singleton_method("dedup", function!(dedup, 4))?;
         
     | 
| 
       12 
     | 
    
         
            -
                module.define_singleton_method("to_csv", function!(to_csv,  
     | 
| 
       13 
     | 
    
         
            -
                module.define_singleton_method("transform_csv", function!(transform_csv,  
     | 
| 
      
 12 
     | 
    
         
            +
                module.define_singleton_method("to_csv", function!(to_csv, 7))?;
         
     | 
| 
      
 13 
     | 
    
         
            +
                module.define_singleton_method("transform_csv", function!(transform_csv, 7))?;
         
     | 
| 
       14 
14 
     | 
    
         
             
                Ok(())
         
     | 
| 
       15 
15 
     | 
    
         
             
            }
         
     | 
| 
         @@ -1,16 +1,17 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            use std::collections::HashMap;
         
     | 
| 
       2 
     | 
    
         
            -
            use std::fs::File;
         
     | 
| 
       3 
1 
     | 
    
         
             
            use chrono::{NaiveDate, NaiveDateTime, NaiveTime, Utc};
         
     | 
| 
       4 
2 
     | 
    
         
             
            use csv::{Reader, StringRecord, Writer};
         
     | 
| 
       5 
3 
     | 
    
         
             
            use magnus::{Error, RArray, Ruby};
         
     | 
| 
      
 4 
     | 
    
         
            +
            use std::collections::HashMap;
         
     | 
| 
      
 5 
     | 
    
         
            +
            use std::fs::File;
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
            use crate::utils::{ 
     | 
| 
      
 7 
     | 
    
         
            +
            use crate::utils::{check_mandatory_headers, create_header_map, headers_as_byte_record, index_of_header_in_mandatory_list, magnus_err, missing_header, missing_value, to_datetime_error, FileExtension};
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
9 
     | 
    
         
             
            pub fn transform_csv(ruby: &Ruby, csv_path: String,
         
     | 
| 
       10 
10 
     | 
    
         
             
                                 target_path: String, exclusions: RArray,
         
     | 
| 
       11 
11 
     | 
    
         
             
                                 mandatory_headers: RArray,
         
     | 
| 
       12 
12 
     | 
    
         
             
                                 status_exclusions: RArray,
         
     | 
| 
       13 
     | 
    
         
            -
                                 expected_trust_name: String, 
     | 
| 
      
 13 
     | 
    
         
            +
                                 expected_trust_name: String,
         
     | 
| 
      
 14 
     | 
    
         
            +
                                 is_streamed_file: bool) -> magnus::error::Result<()> {
         
     | 
| 
       14 
15 
     | 
    
         
             
                if !csv_path.has_extension(&["csv"]) {
         
     | 
| 
       15 
16 
     | 
    
         
             
                    return Err(Error::new(ruby.exception_standard_error(), "csv_path must be a csv file".to_string()));
         
     | 
| 
       16 
17 
     | 
    
         
             
                }
         
     | 
| 
         @@ -60,7 +61,9 @@ pub fn transform_csv(ruby: &Ruby, csv_path: String, 
     | 
|
| 
       60 
61 
     | 
    
         
             
                        let column_value = record.get(*column_index).ok_or(missing_value(ruby, column))?;
         
     | 
| 
       61 
62 
     | 
    
         
             
                        let column_value = column_value.trim_end();
         
     | 
| 
       62 
63 
     | 
    
         | 
| 
       63 
     | 
    
         
            -
                         
     | 
| 
      
 64 
     | 
    
         
            +
                        if !is_streamed_file {
         
     | 
| 
      
 65 
     | 
    
         
            +
                            validate_trust_name(ruby, &expected_trust_name, trust_name, i, &column_value.to_string())?;
         
     | 
| 
      
 66 
     | 
    
         
            +
                        }
         
     | 
| 
       64 
67 
     | 
    
         | 
| 
       65 
68 
     | 
    
         
             
                        if i == *date {
         
     | 
| 
       66 
69 
     | 
    
         
             
                            let current = string_to_datetime(column_value).ok_or(to_datetime_error(ruby, column_value, ri, "Date"))?;
         
     | 
| 
         @@ -88,10 +91,11 @@ pub fn transform_csv(ruby: &Ruby, csv_path: String, 
     | 
|
| 
       88 
91 
     | 
    
         
             
            }
         
     | 
| 
       89 
92 
     | 
    
         | 
| 
       90 
93 
     | 
    
         | 
| 
       91 
     | 
    
         
            -
            fn validate_trust_name(ruby: &Ruby, expected_trust_name: &String, trust_name: &usize,  
     | 
| 
      
 94 
     | 
    
         
            +
            fn validate_trust_name(ruby: &Ruby, expected_trust_name: &String, trust_name: &usize, i: usize, s: &String) -> magnus::error::Result<()> {
         
     | 
| 
       92 
95 
     | 
    
         
             
                if i == *trust_name {
         
     | 
| 
      
 96 
     | 
    
         
            +
                    let s = s.trim();
         
     | 
| 
       93 
97 
     | 
    
         
             
                    if s != &expected_trust_name.clone() {
         
     | 
| 
       94 
     | 
    
         
            -
                        return Err( 
     | 
| 
      
 98 
     | 
    
         
            +
                        return Err(Error::new(ruby.exception_standard_error(), format!("Trust actual name: '{}' is not as expected: '{}'", s, expected_trust_name)));
         
     | 
| 
       95 
99 
     | 
    
         
             
                    }
         
     | 
| 
       96 
100 
     | 
    
         
             
                }
         
     | 
| 
       97 
101 
     | 
    
         
             
                Ok(())
         
     | 
| 
         @@ -2,11 +2,11 @@ use std::collections::HashMap; 
     | 
|
| 
       2 
2 
     | 
    
         
             
            use std::fs::File;
         
     | 
| 
       3 
3 
     | 
    
         
             
            use std::io::{BufWriter, Write};
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
            use calamine::{ 
     | 
| 
      
 5 
     | 
    
         
            +
            use calamine::{open_workbook_auto, Data, Range, Reader};
         
     | 
| 
       6 
6 
     | 
    
         
             
            use chrono::{NaiveDateTime, Timelike, Utc};
         
     | 
| 
       7 
7 
     | 
    
         
             
            use magnus::{RArray, Ruby};
         
     | 
| 
       8 
8 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
            use crate::utils::{ 
     | 
| 
      
 9 
     | 
    
         
            +
            use crate::utils::{check_mandatory_headers, index_of_header_in_mandatory_list, magnus_err, missing_header, missing_value, to_datetime_error, FileExtension};
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
            pub fn to_csv(ruby: &Ruby, xls_path: String,
         
     | 
| 
       12 
12 
     | 
    
         
             
                          target_path: String,
         
     | 
| 
         @@ -14,6 +14,7 @@ pub fn to_csv(ruby: &Ruby, xls_path: String, 
     | 
|
| 
       14 
14 
     | 
    
         
             
                          mandatory_headers: RArray,
         
     | 
| 
       15 
15 
     | 
    
         
             
                          status_exclusions: RArray,
         
     | 
| 
       16 
16 
     | 
    
         
             
                          expected_trust_name: String,
         
     | 
| 
      
 17 
     | 
    
         
            +
                          is_streamed_file: bool
         
     | 
| 
       17 
18 
     | 
    
         
             
            ) -> magnus::error::Result<()> {
         
     | 
| 
       18 
19 
     | 
    
         
             
                if !xls_path.has_extension(&["xls","xlsx"]) {
         
     | 
| 
       19 
20 
     | 
    
         
             
                    return Err(magnus::Error::new(ruby.exception_standard_error(), "xls_path must be an xls or xlsx file".to_string()));
         
     | 
| 
         @@ -40,7 +41,7 @@ pub fn to_csv(ruby: &Ruby, xls_path: String, 
     | 
|
| 
       40 
41 
     | 
    
         
             
                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()))?;
         
     | 
| 
       41 
42 
     | 
    
         
             
                let mut dest = BufWriter::new(csv_out_file);
         
     | 
| 
       42 
43 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
                write_csv(ruby, &mut dest, &range, header_map, exclusions, mandatory_headers, headers_list, status_exclusions, expected_trust_name)
         
     | 
| 
      
 44 
     | 
    
         
            +
                write_csv(ruby, &mut dest, &range, header_map, exclusions, mandatory_headers, headers_list, status_exclusions, expected_trust_name, is_streamed_file)
         
     | 
| 
       44 
45 
     | 
    
         
             
            }
         
     | 
| 
       45 
46 
     | 
    
         | 
| 
       46 
47 
     | 
    
         
             
            fn write_csv<W: Write>(ruby: &Ruby, dest: &mut W, range: &Range<Data>,
         
     | 
| 
         @@ -48,7 +49,8 @@ fn write_csv<W: Write>(ruby: &Ruby, dest: &mut W, range: &Range<Data>, 
     | 
|
| 
       48 
49 
     | 
    
         
             
                                   mandatory_headers: Vec<String>,
         
     | 
| 
       49 
50 
     | 
    
         
             
                                   headers_list: Vec<String>,
         
     | 
| 
       50 
51 
     | 
    
         
             
                                   status_exclusions: Vec<String>,
         
     | 
| 
       51 
     | 
    
         
            -
                                   expected_trust_name: String 
     | 
| 
      
 52 
     | 
    
         
            +
                                   expected_trust_name: String,
         
     | 
| 
      
 53 
     | 
    
         
            +
                                   is_streamed_file: bool) -> magnus::error::Result<()> {
         
     | 
| 
       52 
54 
     | 
    
         
             
                let n = mandatory_headers.len() - 1;
         
     | 
| 
       53 
55 
     | 
    
         
             
                let request_id = header_map.get("Request Id").ok_or(missing_header(ruby, "Request Id"))?;
         
     | 
| 
       54 
56 
     | 
    
         
             
                let date = header_map.get("Date").ok_or(missing_header(ruby, "Date"))?;
         
     | 
| 
         @@ -71,7 +73,10 @@ fn write_csv<W: Write>(ruby: &Ruby, dest: &mut W, range: &Range<Data>, 
     | 
|
| 
       71 
73 
     | 
    
         
             
                    if date_value_is_not_present(&date, &r) {
         
     | 
| 
       72 
74 
     | 
    
         
             
                        return Err(magnus::Error::new(ruby.exception_standard_error(), format!("Date value is not present in row: {}", ri)));
         
     | 
| 
       73 
75 
     | 
    
         
             
                    }
         
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                    if !is_streamed_file {
         
     | 
| 
      
 78 
     | 
    
         
            +
                        validate_trust_name(ruby, &expected_trust_name, trust_name, ri, &r)?;
         
     | 
| 
      
 79 
     | 
    
         
            +
                    }
         
     | 
| 
       75 
80 
     | 
    
         | 
| 
       76 
81 
     | 
    
         
             
                    for (i, c) in mandatory_headers.iter().enumerate() {
         
     | 
| 
       77 
82 
     | 
    
         
             
                        let column_index = header_map.get(c).ok_or(missing_header(ruby, c))?;
         
     | 
| 
         @@ -147,6 +152,7 @@ fn write_csv<W: Write>(ruby: &Ruby, dest: &mut W, range: &Range<Data>, 
     | 
|
| 
       147 
152 
     | 
    
         
             
            fn validate_trust_name(ruby: &Ruby, expected_trust_name: &String, trust_name: &usize, ri: usize, r: &Vec<&Data>) -> magnus::error::Result<()> {
         
     | 
| 
       148 
153 
     | 
    
         
             
                if ri > 0 {
         
     | 
| 
       149 
154 
     | 
    
         
             
                    let s = r[*trust_name].to_string();
         
     | 
| 
      
 155 
     | 
    
         
            +
                    let s = s.trim();
         
     | 
| 
       150 
156 
     | 
    
         
             
                    if s != expected_trust_name.clone() {
         
     | 
| 
       151 
157 
     | 
    
         
             
                        return Err(magnus::Error::new(ruby.exception_standard_error(), format!("Trust actual name: '{}' is not as expected: '{}'", s, expected_trust_name)));
         
     | 
| 
       152 
158 
     | 
    
         
             
                    }
         
     | 
| 
         Binary file 
     | 
| 
         Binary file 
     | 
| 
         Binary file 
     | 
| 
         Binary file 
     | 
    
        data/lib/csv_utils/version.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.21
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: x86_64-linux
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - kingsley.hendrickse
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2025-04-14 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       13 
13 
     | 
    
         
             
            description: Deduplication of CSV files and XLS to CSV conversion.
         
     | 
| 
       14 
14 
     | 
    
         
             
            email:
         
     |