patchwork_csv_utils 0.1.15-aarch64-linux → 0.1.16-aarch64-linux

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: 3672b159471f9f747064d5c615280e3fcee76ffb9dcdc60e237a38452a93b32d
4
- data.tar.gz: 1262d959112a44f7f260e86c19a657cadaf540275e73f4e0d7a456181fa7dc0a
3
+ metadata.gz: 303f1fba53339dc1c5a34072eec44649460de79d8d594f3a59a9a656d302d63c
4
+ data.tar.gz: 4c41792380ad3da07de17b366b09b934063dfa660e7b6b3b165b39e53f80dcb3
5
5
  SHA512:
6
- metadata.gz: e8017f8df3dd1a10382dc9b491c688acbe1becb372dabe1d33e3e46f652019f0c2ce93a39e09a3ade533fc9c216172998f6f134e5f4e845408e1c32c6a20b276
7
- data.tar.gz: 8f7484396d68e3c715c9013c93983ce1b58a5b754a1ba4841830a5e540912ecae8c53f447a2757ca3558bb95e76f67d9e8103d890817cc2ca19de6dfc147a19b
6
+ metadata.gz: 0d9938712374b5409eafcd42eebcaa21b0fe220f4198aab91e3da44cf3052c4a5baf9c90e34b307c542de4667a1edeb7f1d64025061fe27d5a693b85900f1b67
7
+ data.tar.gz: d11877e4bc89460b2090f4f1853ef3b82403ff744b3b55ad1ec7a4aea961b42ed38d4f121f36f4ed647f7af0cc9e88ba338b969f8d71146939a706b9bbbcbfb1
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: aarch64-linux
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: