patchwork_csv_utils 0.1.15-arm64-darwin → 0.1.16-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: 14f80b793a82a72259a5109f10fe4819209d5678b0dfb9e9625f1dcbe369032c
4
- data.tar.gz: 88eb4c82a01f9aefed47a4004b0ee3aab5c06c797f13037782379d2652aabb97
3
+ metadata.gz: 8bc0fc6a96beb105819f545deea0461cecdd83b279ed83fa37034801cb3bcab7
4
+ data.tar.gz: 619cd75e95bb9ae03bf583446f10aa35cd95e39cc8c38f9acdd480e90bcd82d7
5
5
  SHA512:
6
- metadata.gz: ab3d39f423189c11331d585572f6a574d2e77a6b66f67172c4ab82b1c0185b4a251a1cee58e4cbbee361d5a8651a9bf08b7a7d9867cc1e45f47d2e06cd1a8a3c
7
- data.tar.gz: b20cfb0ac285189a58f879b4ded074bac5886c780afb7bef983809e8689e9ee24d13f923ec633094e150be528d84702ba3585e28f8951974b4495727c6efb4d7
6
+ metadata.gz: d6212b706fa1feaf0d5200c291977ef372fadf9c2c35038211082c58b4e531b6fb1e08d01efd741f087a9c80fdbaa7f1135409fdc28b99a08262b61b883527a4
7
+ data.tar.gz: 69e2868e1e9bf8f57874457fafa6857b58cd9236a7677806fe716fb779bb6cd620e3497b75b9c5aef6006e5073b5115dfdfd5d04b61ec60aff9891ef1d07839c
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: arm64-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: