dedup_csv 0.1.0-x86_64-linux-musl → 0.1.1-x86_64-linux-musl

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: 3fd679aa79b8440e5b65df12e5691e3dc7bc28cbc5ec7854b5000f9d42ba9b22
4
- data.tar.gz: 5d53342cf426de5305da821025ed27e5b9017dcf4127671877377f14fde9bd79
3
+ metadata.gz: c8d96c1554006e43d6327794ec8ffa67730660d50afba12addcca2e72551f1fc
4
+ data.tar.gz: 609cf2a07320a051bfbfb46868d4f3d268ee7ee3765ce2834a7c7a64e00887ad
5
5
  SHA512:
6
- metadata.gz: cae9dbfcc4814989551c2208bbf1d305bedbf1d8ab7d7ba985ea24cbe8697c385edbea613168227d1b99bf4c79542089b70665c4ca15d76c1cf3067c21034d10
7
- data.tar.gz: 923ed9468fee9785b6b6bb98a7b314bd9776dbd8a1045db4daab81ecd3bb3d8226e2a9fb2044779ecbea80424eedb0f9ef26d14748e6262b7795a72c40c06166
6
+ metadata.gz: 80fece252c1ddd8701fdb0fa8e070dff2545a82ae49e4d65e7d7c0754cc6fc07b973a5f8c0d8d654c99dedd9207d6be6ad4e68f80e35b44f4bfbda5804b61acd
7
+ data.tar.gz: e78e7dbffaae44de88742c093ca33a374cad402aed48369941a1cb2bfe380af48f9ca5c30d1b36fde7141af23c3d8a420dc2c22544e4c37cbf63a277d0bcf650
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: x86_64-linux-musl
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
@@ -51,6 +54,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
54
  version: 3.3.dev
52
55
  required_rubygems_version: !ruby/object:Gem::Requirement
53
56
  requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 3.0.0
54
60
  - - ">="
55
61
  - !ruby/object:Gem::Version
56
62
  version: 3.3.22