patchwork_csv_utils 0.1.18-x86_64-darwin → 0.1.20-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 +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 -6
 - data/ext/csv_utils/src/utils/xls.rs +9 -7
 - data/lib/csv_utils/2.7/csv_utils.bundle +0 -0
 - data/lib/csv_utils/3.0/csv_utils.bundle +0 -0
 - data/lib/csv_utils/3.1/csv_utils.bundle +0 -0
 - data/lib/csv_utils/3.2/csv_utils.bundle +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: cdf477614b412f9458bb7e3872f2445b8158aff33ea38ca7981f97009acd90cc
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 9efc964090af17af18c8dc570f451b9e82de775bb9fb8c1414c54a4ba299db12
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: b7b9fa6efe358fd8769ab3b16fb7a9c1cbe18bb7330439e9c8c01110c861434cca94df136516d073a5a37b2260887c9d4bdf6c92a7ef92656d6f4a4627486a28
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: e2bd9b85b3277938ed6fddf211e9572399165dd8be8d078da6b0ebe48a8870428fa53448e6991f60a040f3141383b754e69272b4eab40e5d4bd425f667c8efbd
         
     | 
    
        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, 6))?;
         
     | 
| 
      
 13 
     | 
    
         
            +
                module.define_singleton_method("transform_csv", function!(transform_csv, 6))?;
         
     | 
| 
       14 
14 
     | 
    
         
             
                Ok(())
         
     | 
| 
       15 
15 
     | 
    
         
             
            }
         
     | 
| 
         @@ -1,15 +1,16 @@ 
     | 
|
| 
       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 
     | 
    
         
            -
                                 status_exclusions: RArray 
     | 
| 
      
 12 
     | 
    
         
            +
                                 status_exclusions: RArray,
         
     | 
| 
      
 13 
     | 
    
         
            +
                                 expected_trust_name: String,) -> magnus::error::Result<()> {
         
     | 
| 
       13 
14 
     | 
    
         
             
                if !csv_path.has_extension(&["csv"]) {
         
     | 
| 
       14 
15 
     | 
    
         
             
                    return Err(Error::new(ruby.exception_standard_error(), "csv_path must be a csv file".to_string()));
         
     | 
| 
       15 
16 
     | 
    
         
             
                }
         
     | 
| 
         @@ -40,6 +41,7 @@ pub fn transform_csv(ruby: &Ruby, csv_path: String, 
     | 
|
| 
       40 
41 
     | 
    
         
             
                let actual_start = header_map.get("Actual Start").ok_or(missing_header(ruby, "Actual Start"))?;
         
     | 
| 
       41 
42 
     | 
    
         
             
                let actual_end = header_map.get("Actual End").ok_or(missing_header(ruby, "Actual End"))?;
         
     | 
| 
       42 
43 
     | 
    
         
             
                let status = header_map.get("Status");
         
     | 
| 
      
 44 
     | 
    
         
            +
                let trust_name = header_map.get("Trust").ok_or(missing_header(ruby, "Trust"))?;
         
     | 
| 
       43 
45 
     | 
    
         | 
| 
       44 
46 
     | 
    
         
             
                let mandatory_records = get_mandatory_records(&ruby, &mut csv, &headers_list, &mandatory_headers)?;
         
     | 
| 
       45 
47 
     | 
    
         | 
| 
         @@ -58,6 +60,8 @@ pub fn transform_csv(ruby: &Ruby, csv_path: String, 
     | 
|
| 
       58 
60 
     | 
    
         
             
                        let column_value = record.get(*column_index).ok_or(missing_value(ruby, column))?;
         
     | 
| 
       59 
61 
     | 
    
         
             
                        let column_value = column_value.trim_end();
         
     | 
| 
       60 
62 
     | 
    
         | 
| 
      
 63 
     | 
    
         
            +
                        validate_trust_name(ruby, &expected_trust_name, trust_name, i, &column_value.to_string())?;
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
       61 
65 
     | 
    
         
             
                        if i == *date {
         
     | 
| 
       62 
66 
     | 
    
         
             
                            let current = string_to_datetime(column_value).ok_or(to_datetime_error(ruby, column_value, ri, "Date"))?;
         
     | 
| 
       63 
67 
     | 
    
         
             
                            date_value = current;
         
     | 
| 
         @@ -84,10 +88,11 @@ pub fn transform_csv(ruby: &Ruby, csv_path: String, 
     | 
|
| 
       84 
88 
     | 
    
         
             
            }
         
     | 
| 
       85 
89 
     | 
    
         | 
| 
       86 
90 
     | 
    
         | 
| 
       87 
     | 
    
         
            -
            fn validate_trust_name(ruby: &Ruby, expected_trust_name: &String, trust_name: &usize,  
     | 
| 
      
 91 
     | 
    
         
            +
            fn validate_trust_name(ruby: &Ruby, expected_trust_name: &String, trust_name: &usize, i: usize, s: &String) -> magnus::error::Result<()> {
         
     | 
| 
       88 
92 
     | 
    
         
             
                if i == *trust_name {
         
     | 
| 
      
 93 
     | 
    
         
            +
                    let s = s.trim();
         
     | 
| 
       89 
94 
     | 
    
         
             
                    if s != &expected_trust_name.clone() {
         
     | 
| 
       90 
     | 
    
         
            -
                        return Err( 
     | 
| 
      
 95 
     | 
    
         
            +
                        return Err(Error::new(ruby.exception_standard_error(), format!("Trust actual name: '{}' is not as expected: '{}'", s, expected_trust_name)));
         
     | 
| 
       91 
96 
     | 
    
         
             
                    }
         
     | 
| 
       92 
97 
     | 
    
         
             
                }
         
     | 
| 
       93 
98 
     | 
    
         
             
                Ok(())
         
     | 
| 
         @@ -2,17 +2,18 @@ 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,
         
     | 
| 
       13 
13 
     | 
    
         
             
                          exclusions: RArray,
         
     | 
| 
       14 
14 
     | 
    
         
             
                          mandatory_headers: RArray,
         
     | 
| 
       15 
15 
     | 
    
         
             
                          status_exclusions: RArray,
         
     | 
| 
      
 16 
     | 
    
         
            +
                          expected_trust_name: String,
         
     | 
| 
       16 
17 
     | 
    
         
             
            ) -> magnus::error::Result<()> {
         
     | 
| 
       17 
18 
     | 
    
         
             
                if !xls_path.has_extension(&["xls","xlsx"]) {
         
     | 
| 
       18 
19 
     | 
    
         
             
                    return Err(magnus::Error::new(ruby.exception_standard_error(), "xls_path must be an xls or xlsx file".to_string()));
         
     | 
| 
         @@ -22,11 +23,9 @@ pub fn to_csv(ruby: &Ruby, xls_path: String, 
     | 
|
| 
       22 
23 
     | 
    
         
             
                let mandatory_headers: Vec<String> = RArray::to_vec(mandatory_headers)?;
         
     | 
| 
       23 
24 
     | 
    
         
             
                let status_exclusions = RArray::to_vec(status_exclusions)?;
         
     | 
| 
       24 
25 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
26 
     | 
    
         
             
                let mut workbook = open_workbook_auto(&xls_path)
         
     | 
| 
       27 
27 
     | 
    
         
             
                    .map_err(|e| magnus_err(ruby, e, format!("could not open workbook: {}", xls_path).as_str()))?;
         
     | 
| 
       28 
28 
     | 
    
         | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
29 
     | 
    
         
             
                let range = workbook.worksheet_range_at(0)
         
     | 
| 
       31 
30 
     | 
    
         
             
                    .ok_or(magnus::Error::new(ruby.exception_standard_error(), "no worksheet found in xls".to_string()))
         
     | 
| 
       32 
31 
     | 
    
         
             
                    .and_then(|r| r.map_err(|e| magnus_err(ruby, e, "could not read worksheet range")))?;
         
     | 
| 
         @@ -41,14 +40,15 @@ pub fn to_csv(ruby: &Ruby, xls_path: String, 
     | 
|
| 
       41 
40 
     | 
    
         
             
                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()))?;
         
     | 
| 
       42 
41 
     | 
    
         
             
                let mut dest = BufWriter::new(csv_out_file);
         
     | 
| 
       43 
42 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
                write_csv(ruby, &mut dest, &range, header_map, exclusions, mandatory_headers, headers_list, status_exclusions)
         
     | 
| 
      
 43 
     | 
    
         
            +
                write_csv(ruby, &mut dest, &range, header_map, exclusions, mandatory_headers, headers_list, status_exclusions, expected_trust_name)
         
     | 
| 
       45 
44 
     | 
    
         
             
            }
         
     | 
| 
       46 
45 
     | 
    
         | 
| 
       47 
46 
     | 
    
         
             
            fn write_csv<W: Write>(ruby: &Ruby, dest: &mut W, range: &Range<Data>,
         
     | 
| 
       48 
47 
     | 
    
         
             
                                   header_map: HashMap<String, usize>, exclusions: Vec<String>,
         
     | 
| 
       49 
48 
     | 
    
         
             
                                   mandatory_headers: Vec<String>,
         
     | 
| 
       50 
49 
     | 
    
         
             
                                   headers_list: Vec<String>,
         
     | 
| 
       51 
     | 
    
         
            -
                                   status_exclusions: Vec<String 
     | 
| 
      
 50 
     | 
    
         
            +
                                   status_exclusions: Vec<String>,
         
     | 
| 
      
 51 
     | 
    
         
            +
                                   expected_trust_name: String) -> magnus::error::Result<()> {
         
     | 
| 
       52 
52 
     | 
    
         
             
                let n = mandatory_headers.len() - 1;
         
     | 
| 
       53 
53 
     | 
    
         
             
                let request_id = header_map.get("Request Id").ok_or(missing_header(ruby, "Request Id"))?;
         
     | 
| 
       54 
54 
     | 
    
         
             
                let date = header_map.get("Date").ok_or(missing_header(ruby, "Date"))?;
         
     | 
| 
         @@ -57,6 +57,7 @@ fn write_csv<W: Write>(ruby: &Ruby, dest: &mut W, range: &Range<Data>, 
     | 
|
| 
       57 
57 
     | 
    
         
             
                let actual_start = header_map.get("Actual Start").ok_or(missing_header(ruby, "Actual Start"))?;
         
     | 
| 
       58 
58 
     | 
    
         
             
                let actual_end = header_map.get("Actual End").ok_or(missing_header(ruby, "Actual End"))?;
         
     | 
| 
       59 
59 
     | 
    
         
             
                let status = header_map.get("Status");
         
     | 
| 
      
 60 
     | 
    
         
            +
                let trust_name = header_map.get("Trust").ok_or(missing_header(ruby, "Trust"))?;
         
     | 
| 
       60 
61 
     | 
    
         | 
| 
       61 
62 
     | 
    
         
             
                let mandatory_rows = get_mandatory_records(ruby, range, &headers_list, &mandatory_headers)?;
         
     | 
| 
       62 
63 
     | 
    
         | 
| 
         @@ -70,7 +71,7 @@ fn write_csv<W: Write>(ruby: &Ruby, dest: &mut W, range: &Range<Data>, 
     | 
|
| 
       70 
71 
     | 
    
         
             
                    if date_value_is_not_present(&date, &r) {
         
     | 
| 
       71 
72 
     | 
    
         
             
                        return Err(magnus::Error::new(ruby.exception_standard_error(), format!("Date value is not present in row: {}", ri)));
         
     | 
| 
       72 
73 
     | 
    
         
             
                    }
         
     | 
| 
       73 
     | 
    
         
            -
                     
     | 
| 
      
 74 
     | 
    
         
            +
                    validate_trust_name(ruby, &expected_trust_name, trust_name, ri, &r)?;
         
     | 
| 
       74 
75 
     | 
    
         | 
| 
       75 
76 
     | 
    
         
             
                    for (i, c) in mandatory_headers.iter().enumerate() {
         
     | 
| 
       76 
77 
     | 
    
         
             
                        let column_index = header_map.get(c).ok_or(missing_header(ruby, c))?;
         
     | 
| 
         @@ -146,6 +147,7 @@ fn write_csv<W: Write>(ruby: &Ruby, dest: &mut W, range: &Range<Data>, 
     | 
|
| 
       146 
147 
     | 
    
         
             
            fn validate_trust_name(ruby: &Ruby, expected_trust_name: &String, trust_name: &usize, ri: usize, r: &Vec<&Data>) -> magnus::error::Result<()> {
         
     | 
| 
       147 
148 
     | 
    
         
             
                if ri > 0 {
         
     | 
| 
       148 
149 
     | 
    
         
             
                    let s = r[*trust_name].to_string();
         
     | 
| 
      
 150 
     | 
    
         
            +
                    let s = s.trim();
         
     | 
| 
       149 
151 
     | 
    
         
             
                    if s != expected_trust_name.clone() {
         
     | 
| 
       150 
152 
     | 
    
         
             
                        return Err(magnus::Error::new(ruby.exception_standard_error(), format!("Trust actual name: '{}' is not as expected: '{}'", s, expected_trust_name)));
         
     | 
| 
       151 
153 
     | 
    
         
             
                    }
         
     | 
| 
         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.20
         
     | 
| 
       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- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2024-12-05 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       13 
13 
     | 
    
         
             
            description: Deduplication of CSV files and XLS to CSV conversion.
         
     | 
| 
       14 
14 
     | 
    
         
             
            email:
         
     |