patchwork_csv_utils 0.1.7-x86_64-darwin → 0.1.8-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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6716d509dcd08fa0114772079eb4ee4c910d9fcba2e239292661f7394ae20579
4
- data.tar.gz: 97b20c9b75784359b32bf352156827c62f1d63d29cb00833ce826ae9db1ba08a
3
+ metadata.gz: 6603f8bcfc0587d4d92642e938c58f3077e7cc22a3147de6cc11ad83f562d337
4
+ data.tar.gz: 4b8e33dcd5fa853d8f9a95420d6f844645dc552f16651e91458c6429f92b67b3
5
5
  SHA512:
6
- metadata.gz: 4cb36630ed56de19331bc54206aaed38cfe1901b68ca4b4822c16d5141d8f0a7e374fa1c508b951dbf9182bcef3ffa5f2e0c8fa116b4ed63b148f6ebbddbf076
7
- data.tar.gz: 5cc6c6c1a0edf9ef86b42fab23aaa2937b1a80fcad5518a1f15fd3fe22d0ace8d3a534bac85f46a83a25a1dadc6328d210806f616f561dc9fb5bbe712e2f5a8b
6
+ metadata.gz: a1102ac2ad779f7077324871702edb4597157715aae11fda27081c40dc6708aed94549053f4895ceb9dafcc862740de6b83b7cce09d770593bcf62dcb5fc1ed0
7
+ data.tar.gz: e33c5a1e1e521af86d6391093a7f0a5be3b77f733dad77e1114817aea944cd2788aa59b59b0aac94e0fbf82654ce0669c165f55966dc8d64ca0442b660becc22
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- patchwork_csv_utils (0.1.7)
4
+ patchwork_csv_utils (0.1.8)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -67,4 +67,4 @@ DEPENDENCIES
67
67
  rubocop (~> 1.21)
68
68
 
69
69
  BUNDLED WITH
70
- 2.4.4
70
+ 2.4.10
@@ -19,6 +19,7 @@ pub fn transform_csv(ruby: &Ruby, csv_path: String, target_path: String, exclusi
19
19
  let mut wtr = Writer::from_path(target_path).map_err(|e| magnus_err(ruby, e, "target_path"))?;
20
20
  let headers = csv.headers().map_err(|e| magnus_err(ruby, e, "csv_path headers"))?;
21
21
  let header_map: HashMap<String, usize> = headers.iter().enumerate().map(|(i, h)| (h.to_string(), i)).collect();
22
+ let inverse_header_map: HashMap<usize, String> = headers.iter().enumerate().map(|(i, h)| (i, h.to_string())).collect();
22
23
 
23
24
  wtr.write_byte_record(headers.as_byte_record()).map_err(|e| magnus_err(ruby, e, "write_byte_record"))?;
24
25
 
@@ -41,11 +42,14 @@ pub fn transform_csv(ruby: &Ruby, csv_path: String, target_path: String, exclusi
41
42
  let record = record.iter().enumerate().map(|(i, c)| {
42
43
  let c = c.trim_end();
43
44
  if i == *date {
44
- let current = string_to_datetime(c).ok_or(to_datetime_error(ruby, c, ri, i))?;
45
+ let current = string_to_datetime(c).ok_or(to_datetime_error(ruby, c, ri, "Date"))?;
45
46
  date_value = current;
46
47
  Ok(current.to_string())
47
48
  } else if i == *start || i == *end || i == *actual_start || i == *actual_end {
48
- let current_time = string_to_time(c).ok_or(to_datetime_error(ruby, c, ri, i))?;
49
+ if c.is_empty() { return Ok(c.to_string()); }
50
+ let unknown = "Unknown".to_string();
51
+ let column_name = inverse_header_map.get(&i).unwrap_or(&unknown);
52
+ let current_time = string_to_time(c).ok_or(to_datetime_error(ruby, c, ri, column_name))?;
49
53
  let datetime = transform_time_to_datetime(date_value, current_time);
50
54
  Ok(datetime.to_string())
51
55
  } else {
@@ -79,7 +83,7 @@ fn transform_time_to_datetime(t1: NaiveDateTime, t2: NaiveTime) -> NaiveDateTime
79
83
  NaiveDateTime::new(t1.date(), t2)
80
84
  }
81
85
 
82
- fn to_datetime_error(ruby: &Ruby, value: &str, row: usize, col: usize) -> magnus::Error {
86
+ fn to_datetime_error(ruby: &Ruby, value: &str, row: usize, col: &str) -> magnus::Error {
83
87
  magnus::Error::new(ruby.exception_standard_error(), format!("Could not parse datetime '{}', row: {}, col: {}", value, row, col))
84
88
  }
85
89
 
@@ -44,6 +44,9 @@ fn write_csv<W: Write>(ruby: &Ruby, dest: &mut W, range: &Range<Data>, header_ma
44
44
  if skip_excluded_rows(&request_id, r, &exclusions) { continue; }
45
45
  if skip_empty_rows(r) { continue; }
46
46
  if skip_rows_with_no_request_id(&request_id, r) { continue; }
47
+ if date_value_is_not_present(&date, r) {
48
+ return Err(magnus::Error::new(ruby.exception_standard_error(), format!("Date value is not present in row: {}", ri)));
49
+ }
47
50
 
48
51
  for (i, c) in r.iter().enumerate() {
49
52
  match *c {
@@ -53,7 +56,7 @@ fn write_csv<W: Write>(ruby: &Ruby, dest: &mut W, range: &Range<Data>, header_ma
53
56
  }
54
57
  Data::Float(ref f) => write!(dest, "{}", f),
55
58
  Data::DateTime(ref d) => {
56
- let mut current = d.as_datetime().unwrap_or_default();
59
+ let mut current = d.as_datetime().ok_or(to_datetime_error(ruby, &d.to_string(), ri, "Date"))?;
57
60
  if i == *date {
58
61
  date_value = current;
59
62
  } else if i == *start || i == *end || i == *actual_start || i == *actual_end {
@@ -74,6 +77,10 @@ fn write_csv<W: Write>(ruby: &Ruby, dest: &mut W, range: &Range<Data>, header_ma
74
77
  Ok(())
75
78
  }
76
79
 
80
+ fn date_value_is_not_present(date: &usize, r: &[Data]) -> bool {
81
+ r[*date] == Data::Empty
82
+ }
83
+
77
84
  fn skip_excluded_rows(request_id: &usize, r: &[Data], exclusions: &Vec<String>) -> bool {
78
85
  let value = r[*request_id].to_string();
79
86
  exclusions.contains(&value.to_string())
@@ -91,6 +98,10 @@ fn transform_time_to_datetime(t1: NaiveDateTime, t2: NaiveDateTime) -> NaiveDate
91
98
  NaiveDateTime::new(t1.date(), t2.time())
92
99
  }
93
100
 
101
+ fn to_datetime_error(ruby: &Ruby, value: &str, row: usize, col: &str) -> magnus::Error {
102
+ magnus::Error::new(ruby.exception_standard_error(), format!("Could not parse datetime '{}', row: {}, col: {}", value, row, col))
103
+ }
104
+
94
105
  fn handle_commas<W: Write>(dest: &mut W, s: &str) -> std::io::Result<()> {
95
106
  if s.contains(",") {
96
107
  write!(dest, "{:?}", clean_strings(s).trim_end())
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.7'
4
+ VERSION = '0.1.8'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: patchwork_csv_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: x86_64-darwin
6
6
  authors:
7
7
  - kingsley.hendrickse