dedup_csv 0.1.0-aarch64-linux → 0.1.1-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: 24c8cf7b3478243fbcdbb0003421fd304832e6dcffe45036970a7fe4e249254b
4
- data.tar.gz: 44f14f93eb13a64c32958d98d8f30cee11e66375dd5e73e0332d02b2c634887d
3
+ metadata.gz: dac49f091157d99697ab06da7e76015aa6a3ff430e0967cc2e06d2657214f84b
4
+ data.tar.gz: 3a24bb1f90f549b3a70d490e502ceae73ba75a492ce0d21028c465d1272cfa58
5
5
  SHA512:
6
- metadata.gz: '08706b8b55cbcac8f87e83b045cf2df2c002fcab2ac992a5e61e2dc03fedd49378d867765597dfc5bab2d6e13b8f02152fb1d962b7a01c3694721d80a63cfc46'
7
- data.tar.gz: 1d2d6534f9b91e759a5ff7e03ae44a00916adc9e0ee6325a952676269bf843dfc5b626ba8f7e4fe72705c018acabd0d1db75d9fdbd3dc0e3dfb09a6b56ca14eb
6
+ metadata.gz: 1bcf3b8a3078ba369bed6c987019187e34d2e11873f05e4a99d3c8e6c63f85ec7fcd0d508d618e379c37bd8b066c4fbd82c91dcbd1e882c07fbe7d8c9ae0e16c
7
+ data.tar.gz: 824078534f91b756b3beaca5d944468d3b6c0a49de9bd0ada8f642f48bf04d27a5ca085644e9d030513a4862955058aaf3643ee2d5e931394a39f36b919ca9f5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dedup_csv (0.1.0)
4
+ dedup_csv (0.1.1)
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.10
70
+ 2.4.4
data/README.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  Given 2 CSV files, this gem will create a third CSV file that contains rows from the first CSV file that are not present in the second CSV file.
4
4
 
5
+ ## Installation
6
+
7
+ ```bash
8
+ gem install dedup_csv
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```irb
14
+ require 'dedup_csv/3.2/dedup_csv'
15
+ DedupCsv.dedup('file1.csv', 'file2.csv', 'output.csv')
16
+ ```
17
+
5
18
  ## Contributing
6
19
 
7
20
  Bug reports and pull requests are welcome on GitHub at https://github.com/kingsleyh/dedup_csv.
data/Rakefile CHANGED
@@ -14,11 +14,11 @@ require 'rb_sys/extensiontask'
14
14
  task build: :compile
15
15
 
16
16
  spec = Bundler.load_gemspec('dedup_csv.gemspec')
17
- spec.requirements.clear
18
- spec.required_ruby_version = nil
19
- spec.required_rubygems_version = nil
20
- spec.extensions.clear
21
- spec.files -= Dir['ext/**/*']
17
+ # spec.requirements.clear
18
+ # spec.required_ruby_version = nil
19
+ # spec.required_rubygems_version = nil
20
+ # spec.extensions.clear
21
+ # spec.files -= Dir['ext/**/*']
22
22
 
23
23
  Rake::ExtensionTask.new('dedup_csv', spec) do |c|
24
24
  c.lib_dir = 'lib/dedup_csv'
@@ -0,0 +1,14 @@
1
+ [package]
2
+ name = "dedup_csv"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ authors = ["kingsley.hendrickse <kingsley.hendrickse@patchwork.health>"]
6
+ publish = false
7
+
8
+ [lib]
9
+ crate-type = ["cdylib"]
10
+
11
+ [dependencies]
12
+ magnus = { version = "0.7.1" }
13
+ csv = "1.3.0"
14
+ eyre = "0.6.12"
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mkmf'
4
+ require 'rb_sys/mkmf'
5
+
6
+ create_rust_makefile('dedup_csv/dedup_csv')
@@ -0,0 +1,77 @@
1
+ use std::error::Error;
2
+ use std::ffi::OsStr;
3
+ use std::fs::File;
4
+ use std::path::Path;
5
+ use csv::{StringRecord, Writer};
6
+ use magnus::{define_module, function, prelude::*, Ruby};
7
+
8
+ fn dedup(ruby: &Ruby, previous_csv_path: String, new_csv_path: String, target_path: String) -> magnus::error::Result<()> {
9
+ if !previous_csv_path.has_extension(&["csv"]) {
10
+ return Err(magnus::Error::new(ruby.exception_exception(), "previous_csv_path must be a csv file".to_string()));
11
+ }
12
+ if !new_csv_path.has_extension(&["csv"]) {
13
+ return Err(magnus::Error::new(ruby.exception_exception(), "new_csv_path must be a csv file".to_string()));
14
+ }
15
+
16
+ let csv1 = File::open(previous_csv_path).map_err(|e| magnus_err(ruby, e, "previous_csv_path"))?;
17
+ let csv2 = File::open(new_csv_path).map_err(|e| magnus_err(ruby, e, "new_csv_path"))?;
18
+
19
+ let mut previous_csv: csv::Reader<File> = csv::Reader::from_reader(csv1);
20
+ let mut new_csv: csv::Reader<File> = csv::Reader::from_reader(csv2);
21
+
22
+ let mut wtr = Writer::from_path(target_path).map_err(|e| magnus_err(ruby, e, "target_path"))?;
23
+
24
+ let previous_headers = previous_csv.headers().map_err(|e| magnus_err(ruby, e, "previous_csv_path headers"))?;
25
+ let new_headers = new_csv.headers().map_err(|e| magnus_err(ruby, e, "new_csv_path headers"))?;
26
+
27
+ if previous_headers != new_headers {
28
+ return Err(magnus::Error::new(ruby.exception_exception(), "headers of both csv files must be the same".to_string()));
29
+ }
30
+
31
+ wtr.write_byte_record(previous_headers.as_byte_record()).unwrap();
32
+
33
+ let mut previous_records = vec![];
34
+ for previous_record in previous_csv.records() {
35
+ let previous_record = previous_record.map_err(|e| magnus_err(ruby, e, "previous_record"))?;
36
+ previous_records.push(previous_record)
37
+ }
38
+
39
+ for new_record in new_csv.records() {
40
+ let new_record = new_record.map_err(|e| magnus_err(ruby, e, "new_record"))?;
41
+ if !previous_records.contains(&new_record) {
42
+ let new_record = new_record.into_iter().map(|r| r.trim_end()).collect::<StringRecord>();
43
+ wtr.write_byte_record(new_record.as_byte_record()).unwrap();
44
+ }
45
+ }
46
+
47
+ wtr.flush().unwrap();
48
+
49
+ Ok(())
50
+ }
51
+
52
+ fn magnus_err<E: Error>(ruby: &Ruby, e: E, msg: &str) -> magnus::Error {
53
+ magnus::Error::new(ruby.exception_exception(), format!("{}: {}", msg, e.to_string()))
54
+ }
55
+
56
+ #[magnus::init]
57
+ fn init() -> Result<(), magnus::Error> {
58
+ let module = define_module("DedupCsv")?;
59
+ module.define_singleton_method("dedup", function!(dedup, 3))?;
60
+ Ok(())
61
+ }
62
+
63
+ pub trait FileExtension {
64
+ fn has_extension<S: AsRef<str>>(&self, extensions: &[S]) -> bool;
65
+ }
66
+
67
+ impl<P: AsRef<Path>> FileExtension for P {
68
+ fn has_extension<S: AsRef<str>>(&self, extensions: &[S]) -> bool {
69
+ if let Some(ref extension) = self.as_ref().extension().and_then(OsStr::to_str) {
70
+ return extensions
71
+ .iter()
72
+ .any(|x| x.as_ref().eq_ignore_ascii_case(extension));
73
+ }
74
+
75
+ false
76
+ }
77
+ }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DedupCsv
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dedup_csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - kingsley.hendrickse
@@ -25,6 +25,9 @@ files:
25
25
  - Gemfile.lock
26
26
  - README.md
27
27
  - Rakefile
28
+ - ext/dedup_csv/Cargo.toml
29
+ - ext/dedup_csv/extconf.rb
30
+ - ext/dedup_csv/src/lib.rs
28
31
  - lib/dedup_csv.rb
29
32
  - lib/dedup_csv/2.7/dedup_csv.so
30
33
  - lib/dedup_csv/3.0/dedup_csv.so
@@ -53,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
56
  requirements:
54
57
  - - ">="
55
58
  - !ruby/object:Gem::Version
56
- version: '0'
59
+ version: 3.0.0
57
60
  requirements: []
58
61
  rubygems_version: 3.4.4
59
62
  signing_key: