patchwork_csv_utils 0.1.15-x86_64-darwin → 0.1.16-x86_64-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: c23e4f54406645c9bc0fd8f0fdde1672613c384038f332b12ee4a2c321ec5f7e
4
- data.tar.gz: 56d46f404a0190ae70602cd8940a7378d8b5e61c407633a8052a69db6608f86e
3
+ metadata.gz: c5d1440820a1d43cf883d17038c250ce063de4aefebaa334eac95575adb6dac1
4
+ data.tar.gz: 8779a49dba19537387b4df168e861b890dfb2a33db1e7b85b9648742c17210c2
5
5
  SHA512:
6
- metadata.gz: 9996a7df6d01e1e36c7612958ed2c033309603f7cb0216eefe4b9dc4ca74ef2ce653f3aea5c988fb9d74d04535db58aed1023cb1fc8aadb3ec0076442e889238
7
- data.tar.gz: fccb366c45cddfb7ae30bd78cbcea03c1f8760b0b81e6ae2db58290dc622d6a37dfee8c69b2171d1bea35161c4b93c93f2eb2c88b0c6f4933044e39297499d2f
6
+ metadata.gz: 426b46497c78547b927dce9360f35352212eb3d9a12a2e46198015f314ba2b8d51a73e20f4340a1566bc2f7dc9e47ea47cd570694f8e4c97e7fb9af3bce72a4c
7
+ data.tar.gz: c15ad59179ee3a5a4a0a81da52579eb5545d6e1f4834416cec0bf94d3d89fdd6a60e5e5412275c1203c9e50b30b32c0b43fc5d567cb5c0eb630ad5ddcbea6a56
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- patchwork_csv_utils (0.1.15)
4
+ patchwork_csv_utils (0.1.16)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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, 5))?;
13
- module.define_singleton_method("transform_csv", function!(transform_csv, 5))?;
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,16 +1,16 @@
1
1
  use std::collections::HashMap;
2
2
  use std::fs::File;
3
- use calamine::Data;
4
3
  use chrono::{NaiveDate, NaiveDateTime, NaiveTime, Utc};
5
4
  use csv::{Reader, StringRecord, Writer};
6
5
  use magnus::{Error, RArray, Ruby};
7
6
 
8
- use crate::utils::{FileExtension, magnus_err, missing_header, to_datetime_error, check_mandatory_headers, create_header_map, missing_value, headers_as_byte_record, index_of_header_in_mandatory_list};
7
+ use crate::utils::{FileExtension, magnus_err, missing_header, to_datetime_error, check_mandatory_headers, create_header_map, missing_value, headers_as_byte_record, index_of_header_in_mandatory_list, validate_trust_name};
9
8
 
10
9
  pub fn transform_csv(ruby: &Ruby, csv_path: String,
11
10
  target_path: String, exclusions: RArray,
12
11
  mandatory_headers: RArray,
13
- status_exclusions: RArray) -> magnus::error::Result<()> {
12
+ status_exclusions: RArray,
13
+ expected_trust_name: String,) -> magnus::error::Result<()> {
14
14
  if !csv_path.has_extension(&["csv"]) {
15
15
  return Err(Error::new(ruby.exception_standard_error(), "csv_path must be a csv file".to_string()));
16
16
  }
@@ -41,6 +41,7 @@ pub fn transform_csv(ruby: &Ruby, csv_path: String,
41
41
  let actual_start = header_map.get("Actual Start").ok_or(missing_header(ruby, "Actual Start"))?;
42
42
  let actual_end = header_map.get("Actual End").ok_or(missing_header(ruby, "Actual End"))?;
43
43
  let status = header_map.get("Status");
44
+ let trust_name = header_map.get("Trust").ok_or(missing_header(ruby, "Trust"))?;
44
45
 
45
46
  let mandatory_records = get_mandatory_records(&ruby, &mut csv, &headers_list, &mandatory_headers)?;
46
47
 
@@ -59,6 +60,8 @@ pub fn transform_csv(ruby: &Ruby, csv_path: String,
59
60
  let column_value = record.get(*column_index).ok_or(missing_value(ruby, column))?;
60
61
  let column_value = column_value.trim_end();
61
62
 
63
+ validate_trust_name(ruby, &expected_trust_name, trust_name, ri, i, &column_value.to_string())?;
64
+
62
65
  if i == *date {
63
66
  let current = string_to_datetime(column_value).ok_or(to_datetime_error(ruby, column_value, ri, "Date"))?;
64
67
  date_value = current;
@@ -9,6 +9,15 @@ pub mod csv;
9
9
  pub mod dedup;
10
10
  pub mod xls;
11
11
 
12
+ fn validate_trust_name(ruby: &Ruby, expected_trust_name: &String, trust_name: &usize, ri: usize, i: usize, s: &String) -> magnus::error::Result<()> {
13
+ if ri > 0 && i == *trust_name {
14
+ if s != &expected_trust_name.clone() {
15
+ return Err(magnus::Error::new(ruby.exception_standard_error(), format!("Trust actual name: '{}' is not as expected: '{}'", s, expected_trust_name)));
16
+ }
17
+ }
18
+ Ok(())
19
+ }
20
+
12
21
  fn missing_header(ruby: &Ruby, header: &str) -> magnus::Error {
13
22
  magnus::Error::new(ruby.exception_standard_error(), format!("Missing '{}' header", header))
14
23
  }
@@ -6,13 +6,14 @@ use calamine::{Data, open_workbook, Range, Reader, Xls};
6
6
  use chrono::{NaiveDateTime, Utc};
7
7
  use magnus::{RArray, Ruby};
8
8
 
9
- use crate::utils::{FileExtension, magnus_err, missing_header, to_datetime_error, check_mandatory_headers, missing_value, index_of_header_in_mandatory_list};
9
+ use crate::utils::{FileExtension, magnus_err, missing_header, to_datetime_error, check_mandatory_headers, missing_value, index_of_header_in_mandatory_list, validate_trust_name};
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"]) {
18
19
  return Err(magnus::Error::new(ruby.exception_standard_error(), "xls_path must be an xls file".to_string()));
@@ -37,14 +38,15 @@ pub fn to_csv(ruby: &Ruby, xls_path: String,
37
38
  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()))?;
38
39
  let mut dest = BufWriter::new(csv_out_file);
39
40
 
40
- write_csv(ruby, &mut dest, &range, header_map, exclusions, mandatory_headers, headers_list, status_exclusions)
41
+ write_csv(ruby, &mut dest, &range, header_map, exclusions, mandatory_headers, headers_list, status_exclusions, expected_trust_name)
41
42
  }
42
43
 
43
44
  fn write_csv<W: Write>(ruby: &Ruby, dest: &mut W, range: &Range<Data>,
44
45
  header_map: HashMap<String, usize>, exclusions: Vec<String>,
45
46
  mandatory_headers: Vec<String>,
46
47
  headers_list: Vec<String>,
47
- status_exclusions: Vec<String>) -> magnus::error::Result<()> {
48
+ status_exclusions: Vec<String>,
49
+ expected_trust_name: String) -> magnus::error::Result<()> {
48
50
  let n = mandatory_headers.len() - 1;
49
51
  let request_id = header_map.get("Request Id").ok_or(missing_header(ruby, "Request Id"))?;
50
52
  let date = header_map.get("Date").ok_or(missing_header(ruby, "Date"))?;
@@ -53,6 +55,7 @@ fn write_csv<W: Write>(ruby: &Ruby, dest: &mut W, range: &Range<Data>,
53
55
  let actual_start = header_map.get("Actual Start").ok_or(missing_header(ruby, "Actual Start"))?;
54
56
  let actual_end = header_map.get("Actual End").ok_or(missing_header(ruby, "Actual End"))?;
55
57
  let status = header_map.get("Status");
58
+ let trust_name = header_map.get("Trust").ok_or(missing_header(ruby, "Trust"))?;
56
59
 
57
60
  let mandatory_rows = get_mandatory_records(ruby, range, &headers_list, &mandatory_headers)?;
58
61
 
@@ -74,6 +77,7 @@ fn write_csv<W: Write>(ruby: &Ruby, dest: &mut W, range: &Range<Data>,
74
77
  match *c {
75
78
  Data::Empty => Ok(()),
76
79
  Data::String(ref s) | Data::DateTimeIso(ref s) | Data::DurationIso(ref s) => {
80
+ validate_trust_name(ruby, &expected_trust_name, trust_name, ri, i, s)?;
77
81
  handle_commas(dest, s)
78
82
  }
79
83
  Data::Float(ref f) => write!(dest, "{}", f),
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.15'
4
+ VERSION = '0.1.16'
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.15
4
+ version: 0.1.16
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-10-31 00:00:00.000000000 Z
11
+ date: 2024-11-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Deduplication of CSV files and XLS to CSV conversion.
14
14
  email: